Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Unused helper class causing a null pointer exception.


    randalthor

    Recommended Posts

    Never mind I think I found the reason. When the exception is thrown on onStart(), it stops the onStart() method and prevents the "arrays" field I use in onLoop() from being having its nodes added.

     

    Not knowing what else to do with my version of the AIO fisher under tutorials using nodes, I started to remove things I had added until I reached a point where the null pointer stopped being thrown. For some reason removing

    the field: private RandsAPIMethods method;

    onStart: method = new RandsAPIMethods(this);

    and import: import rand.dreambot.RandsAPIMethods;

    from the main program was enough to get it so stop working again, This makes no sense to me, since none of those three lines of code are active at all when the script is running since I had already commented out the line of code that used my method. 

    The null pointer happened in onLoop():

     

     

    • [ERROR]18:51:16: Exception has occurred while running! Please report error to developer if problem persists: java.lang.NullPointerException at rand.dreambot.fishingAIO.MainAIOFishing.onLoop(MainAIOFishing.java:77) at org.dreambot.api.script.AbstractScript.run(AbstractScript.java:223) at java.lang.Thread.run(Thread.java:745)   

     

     

    this error happened in the constructor of my helper class which was called onStart()

     

     

    • [ERROR]18:15:10: java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to java.util.ArrayList at rand.dreambot.RandsAPIMethods.(RandsAPIMethods.java:47) at rand.dreambot.RandsAPIMethods.(RandsAPIMethods.java:42) at rand.dreambot.fishingAIO.MainAIOFishing.onStart(MainAIOFishing.java:43) at org.dreambot.api.script.AbstractScript.run(AbstractScript.java:180) at java.lang.Thread.run(Thread.java:745)  

    The RandsAPIMethods constructor had a secondary one which took in a Integer...y as parameters aka a Integer[] 

    the problem was Arrays.asLisy(y) was throwing the exception when I tried to make an ArrayList<Integer>. It looks like arrays.asList returns a List<Integer> which cannot be cast to ArrayList<Integer>

     

     

     

    Here is the code that was throwing the null pointer on execution in onLoop:

     

     

    for(Node a : array) {
    .    if (a != null) {
    .         try {, why was 
    .              if(a.activate()) {
    .                   a.execute();
    .                   break;
    .              }
    .         } catch (InterruptedException e) {
    .     currentState =("interrupted exception");
    .     //e.printStackTrace();
    .   }
    }
    line 77 is the for each loop at the top

     

     

     

    So my main question is, even though I never used my helper class in the program because I commented it out, why was attempting and failing to create an instance of it in onStart() enough to cause an exception to be thrown in the onLoop() which didn't even use the helper class?

    Link to comment
    Share on other sites

    Does the Constructor of your helper class modify the "array" variable used on line 77?

    Yes. I create an array of nodes  that the onLoop() method then runs through and checks to see what to do.

    Link to comment
    Share on other sites

    Yes. I create an array of nodes  that the onLoop() method then runs through and checks to see what to do.

     

    My best guess then would be that the error in the helper class was causing your array variable that contains all your nodes to not properly assign it's values. Therefore causing the null pointer in your onLoop(). 

     

    As far as how to solve the first error you're getting:

    I'd try creating the ArrayList like so:

    ArrayList<Integer> nodes = new ArrayList<Integer>();
    for(Integer inte : intArray){
    	nodes.add(inte);
    }
    

    I Hope this helps ^.^

    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.