Thread: Before posting for help read this! Help format & Common Exceptions

Results 1 to 7 of 7
  1. #1 Before posting for help read this! Help format & Common Exceptions 
    Registered Member
    hacker's Avatar
    Join Date
    Jun 2013
    Posts
    1,409
    Thanks given
    576
    Thanks received
    580
    Rep Power
    5000
    Before I get into this I would like to remind you the following:

    If you are interested in buying or selling help, this is not allowed here, instead go here: Virtual Items

    If you are making a request for reuploads, dumps, developers or etc go here for servers : RS2 Server Requests

    and here for clients/cache: RS2 Client Requests


    Explanation of some common exceptions

    Spoiler for Common Exceptions:


    Spoiler for ArrayIndexOutOfBoundsException:


    An ArrayIndexOutOfBoundsException is thrown when... The Array index is out of bounds.

    An example of this

    Code:
    String[] array= new String[] {"x", "y", "z"};
    
    System.out.println("Here is where exception will be caught" + array[4]);
    This gives you an exception because the indices of the array only go up to 2. If you're wondering why its 2 and not 3 it's because array indices are zero based so doing this
    Code:
    array[3];
    Would also throw an exception.

    How to fix:

    This depends on the situation but usually just extending the array would suffice.

    Code:
    String[] array = new String[] {"x", "y", "z", "1", "2", "3"};
    Would fix the exception I just provided you with. But sometimes extending the array won't actually fix the problem. This is because at times whatever is calling the array is calling the wrong index/indices. Then what you would have to do is make sure it's not calling the wrong index.

    So say you're trying to call for "z". Doing this

    Code:
    String[] array = new String[] {"x", "y", "z"};
    
    System.out.println("Here is where exception will be caught" + array[4]);
    Would throw an exception and if you try extending it then obviously the problem wont be fixed. Instead of extending , this time you're going to have to call the right index so

    Code:
    System.out.println("This will print out the letter z: " + array[2]);


    Spoiler for NullPointerException:


    A Null pointer exceptions can be thrown due to several reasons. e.g taking the length of the null variable

    Code:
    public int[] error;
    
    ...
    
    for (int i = 0; i < error.length; i++) { ...
    "error.length" would throw null pointer because array error is null (hasn't been set)

    what you can do is

    Code:
    public int[] error = {1,2,3};
    Now it's not null



    This would also throw Null pointer

    Code:
    int anyVar = null;
    System.out.println(anyVar);
    Now it's not null




    Spoiler for FileNotFoundException:


    Basically if you're calling for a file/folder or writing into a folder that doesn't exist this will be thrown.

    Manually make the folder/file or use Java to make it!


    For more information visit: https://docs.oracle.com/javase/tutor...al/exceptions/


    Okay so now the most important part. A format in which you can use as reference for how your help post should look like.

    Spoiler for Help Format:

    Describe your problem as best as you can: (please don't write more than needed as it can end up in people not wanting to help, also proof read (re read) what you wrote and make sure it's at least understandable)


    Did you edit anything before this error happened?: (did you touch any code, add any snippets/tutorials etc)


    What exactly triggered this/what were you doing right before error happened?: (self explanatory what goes here)


    Stack trace: (please put them in [CODE] tags)


    Line(s) where error was caught: (this will be included in the stack trace, e.g " at com.client.Model.getModel(Model.java:163)", which would be Line 163 in Model.java, to go to a line usually just open the file and do Control + G and type line #)


    Screenshots: (If you can provide screenshots that will make the situation more understandable it will be beneficial to not only the person helping you but to you too.)

    Attached image
    Reply With Quote  
     

  2. Thankful users:


  3. #2  
    Registered Member
    Join Date
    Dec 2011
    Posts
    793
    Thanks given
    204
    Thanks received
    176
    Rep Power
    173
    This is excellent. Sticky pls
    Reply With Quote  
     

  4. #3  
    Registered Member
    hacker's Avatar
    Join Date
    Jun 2013
    Posts
    1,409
    Thanks given
    576
    Thanks received
    580
    Rep Power
    5000
    Quote Originally Posted by Psychotic View Post
    This is excellent. Sticky pls
    Thanks I hope so. It should help
    Attached image
    Reply With Quote  
     

  5. #4  
    Donator

    Jason's Avatar
    Join Date
    Aug 2009
    Posts
    6,092
    Thanks given
    2,402
    Thanks received
    2,823
    Rep Power
    4550
    Quote Originally Posted by Hacker View Post
    An ArrayIndexOutOfBoundsException is thrown when... The Array index is out of bounds.

    An example of this

    Code:
    String array[] = new String[3];
    
    array = {"x", "y", "z", "1", "2"};
    
    System.out.println("Here is where exception will be caught" + array[4]);
    This gives you an exception because the indices of the array only go up to 2. If you're wondering why its 2 and not 3 it's because array indices are zero based so doing this
    Code:
    array[3];
    Would also throw an exception.

    How to fix:

    This depends on the situation but usually just extending the array would suffice.

    Code:
    String array[] = new int[5];
    Would fix the exception I just provided you with. But sometimes extending the array won't actually fix the problem. This is because at times whatever is calling the array is calling the wrong index/indices. Then what you would have to do is make sure it's not calling the wrong index.

    So say you're trying to call for "z". Doing this

    Code:
    String array[] = new String[3];
    
    array = {"x", "y", "z"};
    
    System.out.println("Here is where exception will be caught" + array[4]);
    Would throw an exception and if you try extending it then obviously the problem wont be fixed. Instead of extending , this time you're going to have to call the right index so

    Code:
    System.out.println("This will print out the letter z: " + array[2]);
    I'm not quite sure what world you're living in but feel free to test some of the nonsense you're spewing out. You initialize an array with a length of 3. Your second line of code doesn't make sense because constants can only be used in initializers. If you did write it properly the length of the new array would be 5, giving 4 new elements meaning no exception would be thrown. Maybe before posting a tutorial you should post a help thread.

    Code:
            String[] array = new String[3];
            
            array = new String[] { "a", "b", "c", "d", "e" };
            
            System.out.println(array[4]);
    Reply With Quote  
     

  6. Thankful user:


  7. #5  
    Registered Member
    hacker's Avatar
    Join Date
    Jun 2013
    Posts
    1,409
    Thanks given
    576
    Thanks received
    580
    Rep Power
    5000
    update: fixed it up a bit in case anyone wanted to know
    Attached image
    Reply With Quote  
     

  8. #6  
    anInt69

    Max _'s Avatar
    Join Date
    Feb 2012
    Age
    26
    Posts
    1,801
    Thanks given
    426
    Thanks received
    727
    Rep Power
    599
    Code:
    public int[] error;
    
    ...
    
    for (int i = 0; i < error.length; i++) { ...
    You wouldn't be able to compile with the usage of the error array without it being initialized prior to use.

    On the other hand..

    Code:
    int anyVar = null;
    System.out.println(anyVar);
    Should throw a nullpointer for you .
    Reply With Quote  
     

  9. #7  
    Registered Member
    hacker's Avatar
    Join Date
    Jun 2013
    Posts
    1,409
    Thanks given
    576
    Thanks received
    580
    Rep Power
    5000
    Quote Originally Posted by Max _ View Post
    Code:
    public int[] error;
    
    ...
    
    for (int i = 0; i < error.length; i++) { ...
    You wouldn't be able to compile with the usage of the error array without it being initialized prior to use.

    On the other hand..

    Code:
    int anyVar = null;
    System.out.println(anyVar);
    Should throw a nullpointer for you .
    Ah alright thanks man :3 as stated above, didnt have much time to write this much less test it
    Attached image
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Replies: 1
    Last Post: 05-06-2015, 08:11 AM
  2. Need your help~ read this thread.
    By bett in forum Help
    Replies: 2
    Last Post: 12-27-2012, 03:37 AM
  3. Please, in need of help; Read this topic.
    By eiowsjio in forum Help
    Replies: 0
    Last Post: 12-07-2010, 06:24 PM
  4. [HELP] Read error [HELP]
    By wooden spoon in forum Help
    Replies: 1
    Last Post: 05-19-2010, 05:04 PM
  5. [HELP] Read Inside [HELP]
    By Tnt Pk in forum RS2 Client
    Replies: 1
    Last Post: 06-30-2008, 02:22 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •