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
  • Try asking for help in the chatbox
  • 2 NPEs


    Kristoffer
     Share

    Recommended Posts

    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

    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

    Can I get the full stacktrace(s)?

    return !FALADOR_FURNACE_AREA.contains(getLocalPlayer())
    

    eerste.png

    if (getWalking().getRunEnergy() > Calculations.random(5, 25))
    

    tweede.png

     

    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

    return !FALADOR_FURNACE_AREA.contains(getLocalPlayer())
    

    eerste.png

    if (getWalking().getRunEnergy() > Calculations.random(5, 25))
    

    tweede.png

     

    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

    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

    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. :P

    Link to comment
    Share on other sites

    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. :P

     

    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. :P

    Edited by Kristoffer
    Link to comment
    Share on other sites

    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. :P

     

    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

    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

     Share

    ×
    ×
    • 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.