Kristoffer 23 Share Posted March 16, 2015 Not sure why I'm getting these NPEs, some help would be nice. The first piece of code that throws an NPE is this: return !FALADOR_FURNACE_AREA.contains(getLocalPlayer()) Not sure if the area is what's throwing the NPE or it can't find the local player or something. (I properly defined the area) Now if I change that code to return true it stops throwing an NPE there, but throws a new one here: if (getWalking().getRunEnergy() > Calculations.random(5, 25)) I've used both pieces of code succesfully on another client but I'm not very used to this one yet so some guidance would be appreciated. Link to comment Share on other sites More sharing options...
Pandemic 2467 Share Posted March 16, 2015 Can I get the full stacktrace(s)? Link to comment Share on other sites More sharing options...
Stormscythe 263 Share Posted March 16, 2015 Not sure why I'm getting these NPEs, some help would be nice. The first piece of code that throws an NPE is this: return !FALADOR_FURNACE_AREA.contains(getLocalPlayer()) Not sure if the area is what's throwing the NPE or it can't find the local player or something. (I properly defined the area) Now if I change that code to return true it stops throwing an NPE there, but throws a new one here: if (getWalking().getRunEnergy() > Calculations.random(5, 25)) I've used both pieces of code succesfully on another client but I'm not very used to this one yet so some guidance would be appreciated. Try using getPlayers().myPlayer() instead of getLocalPlayer() - Sometimes that works, when getLocalPlayer() (atleast that is what I've experienced). Link to comment Share on other sites More sharing options...
Kristoffer 23 Author Share Posted March 16, 2015 Can I get the full stacktrace(s)? return !FALADOR_FURNACE_AREA.contains(getLocalPlayer()) if (getWalking().getRunEnergy() > Calculations.random(5, 25)) The walking code is located at line 34 and I just found out that getWalking().walk(FALADOR_FURNACE_AREA.getRandomTile()); at line 41 is also throwing an NPE. Link to comment Share on other sites More sharing options...
Zawy 849 Share Posted March 16, 2015 return !FALADOR_FURNACE_AREA.contains(getLocalPlayer()) if (getWalking().getRunEnergy() > Calculations.random(5, 25)) The walking code is located at line 34 and I just found out that getWalking().walk(FALADOR_FURNACE_AREA.getRandomTile()); at line 41 is also throwing an NPE. Do you got teamviewer? Mabye I can help you. Link to comment Share on other sites More sharing options...
Kristoffer 23 Author Share Posted March 16, 2015 Try using getPlayers().myPlayer() instead of getLocalPlayer() - Sometimes that works, when getLocalPlayer() (atleast that is what I've experienced). Yeah, noticed in the stack trace that it's getLocalPlayer() that was throwing the NPE, so using getPlayers().myPlayer() solved it, but I'm still getting the other NPEs. Link to comment Share on other sites More sharing options...
Nuclear Nezz 1993 Share Posted March 16, 2015 I'd have to see your full source to get much of an idea on why this is happening. What type of script are you making, Abstract or Task? I think I know why getLocalPlayer() was throwing an NPE, so I fixed that. But the NPE's are thrown on the line in your code, and not inside the methods that you're calling. So getWalking() is returning null. That'd suggest your Instance isn't being created properly. So curious on what type of script you're making so I can try to hunt it down. Link to comment Share on other sites More sharing options...
Kristoffer 23 Author Share Posted March 16, 2015 (edited) I'd have to see your full source to get much of an idea on why this is happening. What type of script are you making, Abstract or Task? I think I know why getLocalPlayer() was throwing an NPE, so I fixed that. But the NPE's are thrown on the line in your code, and not inside the methods that you're calling. So getWalking() is returning null. That'd suggest your Instance isn't being created properly. So curious on what type of script you're making so I can try to hunt it down. I'm extending my main class which extends AbstractScript, does that answer your question? Edit: Yeah, that's what was causing the NPEs, had to create an AbstractScript variable and assign it in the constructor. Fixed. Edited March 16, 2015 by Kristoffer Link to comment Share on other sites More sharing options...
Notorious 341 Share Posted March 16, 2015 I'm extending my main class which extends AbstractScript, does that answer your question? Edit: Yeah, that's what was causing the NPEs, had to create an AbstractScript variable and assign it in the constructor. Fixed. Well if your script extends AbstractScript, then you should have all the access to all the MethodConext methods you need inside that class. I don't believe you would need to create a local variable to use any of the methods as long as your in the same class that extends AbstractScript, if you need access to the methods outside that class, you can always just pass the method context through a parameter as an argument. Link to comment Share on other sites More sharing options...
Kristoffer 23 Author Share Posted March 16, 2015 Well if your script extends AbstractScript, then you should have all the access to all the MethodConext methods you need inside that class. I don't believe you would need to create a local variable to use any of the methods as long as your in the same class that extends AbstractScript, if you need access to the methods outside that class, you can always just pass the method context through a parameter as an argument. The NPEs occured in a subclass of my main class which extends AbstractScript. Link to comment Share on other sites More sharing options...
Recommended Posts