Mephisto Posted December 14, 2018 Share Posted December 14, 2018 (edited) So I wrote a little script and tried to run it. And it gave me this error: java.lang.NullPointerException at org.osbot.rs07.event.InteractionEvent.<init>(zi:86) at Thieverclass.onStart(Thieverclass.java:51) at org.osbot.rs07.event.ScriptExecutor.IIIIiiiiIIii(bp:284) at org.osbot.rs07.event.ScriptExecutor.start(bp:20) at org.osbot.lB.IIIIiiiiIIii(ws:46) at org.osbot.NB.iIiIiiiIiiiI(yab:177) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) How can I fix this? & What does this error mean exactly ? (when I google it I still don't understand it fully) The script I wrote: if (lumbridgeSquare != null){ if (lumbridgeSquare.contains(myPlayer())){ log("Player arrived in Lumbridge"); //Arrived in Lumbridge MethodProvider.sleep(MethodProvider.random(2000, 3000)); getWalking().walk(lTRoute_1); if (lTrapdoor != null){ if (lTrapdoor.isVisible()) { MethodProvider.sleep(MethodProvider.random(1000, 3000)); execute(climbdownTrapdoor); } } } } Edit: Found the flaw, had something to do with reusing an event. Edited December 14, 2018 by Mephisto Quote Link to comment Share on other sites More sharing options...
Fruity Posted December 14, 2018 Share Posted December 14, 2018 (edited) whats on line 51 from Thieverclass? 'at Thieverclass.onStart(Thieverclass.java:51)' looks like you're checking if one thing is not null/visible but then executing an event, are you reusing an event, try making a fresh event before you execute? Edited December 14, 2018 by Fruity 1 Quote Link to comment Share on other sites More sharing options...
dormic Posted December 14, 2018 Share Posted December 14, 2018 at Thieverclass.onStart(Thieverclass.java:51) This is indeed the line where something is NULL, it means that it can't find it, thus can't interact with it. Could you share the exact piece of code at line 51? Then we are able to solve your issue. 1 Quote Link to comment Share on other sites More sharing options...
Mephisto Posted December 14, 2018 Author Share Posted December 14, 2018 22 minutes ago, Fruity said: whats on line 51 from Thieverclass? 'at Thieverclass.onStart(Thieverclass.java:51)' looks like you're checking if one thing is not null/visible but then executing an event, are you reusing an event, try making a fresh event before you execute? I was indeed reusing events. I fixed it now Thanks @Fruity & @dormic for the quick replies ! Quote Link to comment Share on other sites More sharing options...
Script Kid Posted December 14, 2018 Share Posted December 14, 2018 You fixed the problem in this particular case but you didn't find the answers to your original questions so you won't be able to debug your code the next time it happens. Here: 4 hours ago, Mephisto said: What does this error mean exactly ? A null pointer exception is a type of runtime exception that occurs when a null value was used when an object instance was required. Examples include calling methods or accessing fields of a variable that is null. By default all reference (non-primitive) variables in Java are null. Object variableOne = new Object(); Object variableTwo = null; Object variableThree; Only the first variable points to an actual object instance. The second and third variables are both pointing to null. Calling any Object methods from the second or third variables will throw a null pointer exception because the variable is not pointing to a valid Object instance, it's pointing to null. 4 hours ago, Mephisto said: How can I fix this? You always read the stack trace. The null pointer exception occurred on the first line and all the other lines represent the call stack - all the methods that have been called in the program, which eventually resulted in this error: java.lang.NullPointerException at org.osbot.rs07.event.InteractionEvent.<init>(zi:86) < here is where the null pointer exception occurred at Thieverclass.onStart(Thieverclass.java:51) < here is where you called the method that threw the exception at ... at ... ... Usually you are going to fix the first line, because that is where the exception occurred, but in this case the first line is part of the API, which means that you cannot change it. But you can instead change the code from the second line and make sure that you are not passing a null value to the method from the first line. 1 Quote Link to comment Share on other sites More sharing options...
Mephisto Posted December 14, 2018 Author Share Posted December 14, 2018 32 minutes ago, Script Kid said: You fixed the problem in this particular case but you didn't find the answers to your original questions so you won't be able to debug your code the next time it happens. Here: A null pointer exception is a type of runtime exception that occurs when a null value was used when an object instance was required. Examples include calling methods or accessing fields of a variable that is null. By default all reference (non-primitive) variables in Java are null. Object variableOne = new Object(); Object variableTwo = null; Object variableThree; Only the first variable points to an actual object instance. The second and third variables are both pointing to null. Calling any Object methods from the second or third variables will throw a null pointer exception because the variable is not pointing to a valid Object instance, it's pointing to null. You always read the stack trace. The null pointer exception occurred on the first line and all the other lines represent the call stack - all the methods that have been called in the program, which eventually resulted in this error: java.lang.NullPointerException at org.osbot.rs07.event.InteractionEvent.<init>(zi:86) < here is where the null pointer exception occurred at Thieverclass.onStart(Thieverclass.java:51) < here is where you called the method that threw the exception at ... at ... ... Usually you are going to fix the first line, because that is where the exception occurred, but in this case the first line is part of the API, which means that you cannot change it. But you can instead change the code from the second line and make sure that you are not passing a null value to the method from the first line. Thanks for explaining this, I finally get it now . 1 Quote Link to comment Share on other sites More sharing options...