SpareGold 4 Share Posted February 20, 2015 Whenever I gain a level on my chicken killer my console goes crazy with null pointer exceptions. Note that this does not happen if I do not kill the chicken at the same time I gain the level. If the chicekn is able to attack me afterwards and therefore exit the new level message by itself, the problem does not happen. I'm guessing it has something to do with the client not being able to get a handle on the chatbox or something. I have seen in tutorials on this site that people often make their onLoop() like: public int onLoop() throws InterruptedException { //Code Here } and I was wondering if this was the current solution to this problem. Currently my onLoop() does not have the throw because it causes an error in compilation, saying: Exception InterruptedException is not compatible with throws clause in AbstractScript.onLoop() Is anyone able to explain why this happens, or a simple solution to the problem? Note: The chicken killer I am using is very simple and does nothing more than identify a killable chicken(not in combat, nearby, player is not in combat, etc) and attack it. It makes no references to the chatbox or levels. Link to comment Share on other sites More sharing options...
Notorious 342 Share Posted February 20, 2015 Whenever I gain a level on my chicken killer my console goes crazy with null pointer exceptions. Note that this does not happen if I do not kill the chicken at the same time I gain the level. If the chicekn is able to attack me afterwards and therefore exit the new level message by itself, the problem does not happen. I'm guessing it has something to do with the client not being able to get a handle on the chatbox or something. I have seen in tutorials on this site that people often make their onLoop() like: public int onLoop() throws InterruptedException { //Code Here } and I was wondering if this was the current solution to this problem. Currently my onLoop() does not have the throw because it causes an error in compilation, saying: Exception InterruptedException is not compatible with throws clause in AbstractScript.onLoop() Is anyone able to explain why this happens, or a simple solution to the problem? Note: The chicken killer I am using is very simple and does nothing more than identify a killable chicken(not in combat, nearby, player is not in combat, etc) and attack it. It makes no references to the chatbox or levels. If you want, add my skype: notoriouspp So you can explain your issue a bit more, and I should be able to help you out! Link to comment Share on other sites More sharing options...
Kristoffer 24 Share Posted February 20, 2015 Try adding null checks. For example: if (chicken != null) { // Code } Link to comment Share on other sites More sharing options...
Fran 99 Share Posted February 20, 2015 Did you add a method to handle the exception (when the level box appears as dialogue)? If not, on the onLoop(), simply include this dialog, so whenever a dialog occurs, it will click continue. getDialogues().clickContinue(); try public int onLoop() throws InterruptedException //(remove this) { getDialogues().clickContinue(); //Code Here } Link to comment Share on other sites More sharing options...
SpareGold 4 Author Share Posted February 20, 2015 I added what Franjey suggested and have not had the error since. I think I understand the issue, but do you mind explaining how that was the solution to the problem in a little more detail? Like why it caused a null pointer exception? Thanks everyone! And thanks Notorious, I will add you on Skype when I install it on my new PC. Link to comment Share on other sites More sharing options...
Explicit 213 Share Posted February 20, 2015 An InterruptedException is not the same thing as a NullPointerException, idk why you're referencing both if you're just having a npe. The exception only gets thrown if you attempt to call a method on a variable which holds a null reference. Link to comment Share on other sites More sharing options...
Fran 99 Share Posted February 20, 2015 I added what Franjey suggested and have not had the error since. I think I understand the issue, but do you mind explaining how that was the solution to the problem in a little more detail? Like why it caused a null pointer exception? Thanks everyone! And thanks Notorious, I will add you on Skype when I install it on my new PC. Null pointer exception is basically because you're making a call somewhere on a null object. Like if you're getting NPC interaction and there are no NPCs available, it will throw a Null Pointer Exception because NPC is null, so with your script, you're making a call to attack the chicken with a null object which was the dialog box (when it popped up because you levelled and then player kept trying to attack), so you just added a method to handle the null object Link to comment Share on other sites More sharing options...
SpareGold 4 Author Share Posted February 20, 2015 Okay thanks for the explanation! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.