Qubit Posted June 9, 2015 Share Posted June 9, 2015 I get this code when i try to run my code [ERROR][06/09 07:20:59 PM]: Failed to start script [The Al-kharid Hermit] java.lang.reflect.InvocationTargetException at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.osbot.cOn.run(pj:215) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.NullPointerException at alKharidSKiller.AKSkiller.<init>(AKSkiller.java:27) ... 8 more Quote Link to comment Share on other sites More sharing options...
fixthissite Posted June 10, 2015 Share Posted June 10, 2015 (edited) You're getting a NullPointerException at line 27 of AKSkiller.java If you showed the chunk of code surrounding that line, I could help further. My guess is you're trying to use an API method within the constructor of the class that extends Script. Don't use the constructor. Instead, use the onStart method to write code you want to execute when the script starts. Calling things like myPlayer() in the constructor of your script class would result in a NPE, and seeing how you're getting one in the constructor, I'm guessing that's the reason. Edited June 10, 2015 by fixthissite Quote Link to comment Share on other sites More sharing options...
Qubit Posted June 11, 2015 Author Share Posted June 11, 2015 You're getting a NullPointerException at line 27 of AKSkiller.java If you showed the chunk of code surrounding that line, I could help further. My guess is you're trying to use an API method within the constructor of the class that extends Script. Don't use the constructor. Instead, use the onStart method to write code you want to execute when the script starts. Calling things like myPlayer() in the constructor of your script class would result in a NPE, and seeing how you're getting one in the constructor, I'm guessing that's the reason. Quote Link to comment Share on other sites More sharing options...
fixthissite Posted June 11, 2015 Share Posted June 11, 2015 You're getting a NullPointerException at line 27 of AKSkiller.java If you showed the chunk of code surrounding that line, I could help further. My guess is you're trying to use an API method within the constructor of the class that extends Script. Don't use the constructor. Instead, use the onStart method to write code you want to execute when the script starts. Calling things like myPlayer() in the constructor of your script class would result in a NPE, and seeing how you're getting one in the constructor, I'm guessing that's the reason. Yeah, initializing in the field is similar to initializing in the constructor.Assign the values in onStart, not the field. Quote Link to comment Share on other sites More sharing options...
Qubit Posted June 11, 2015 Author Share Posted June 11, 2015 Yeah, initializing in the field is similar to initializing in the constructor. Assign the values in onStart, not the field. Okay thanks ! I'll update once I do that! 1 Quote Link to comment Share on other sites More sharing options...
Bobrocket Posted June 18, 2015 Share Posted June 18, 2015 I'm pretty certain that getWidgets().get(x, y); will actually return a NullPointerException if the widget is not open (citation needed) Fix: if (getWidgets().isVisible(x, y)) { RS2Widget widget = getWidgets().get(x, y); } 1 Quote Link to comment Share on other sites More sharing options...
FrostBug Posted June 19, 2015 Share Posted June 19, 2015 I'm pretty certain that getWidgets().get(x, y); will actually return a NullPointerException if the widget is not open (citation needed) Fix: if (getWidgets().isVisible(x, y)) { RS2Widget widget = getWidgets().get(x, y); } It will not throw an NPE if the widget is not present. It will simply return null Quote Link to comment Share on other sites More sharing options...
Bobrocket Posted June 19, 2015 Share Posted June 19, 2015 It will not throw an NPE if the widget is not present. It will simply return null Right, my apologies. Quote Link to comment Share on other sites More sharing options...