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
  • Unexpected NullPointers


    pharaoh
     Share

    Recommended Posts

    Not sure why I am having such an issue porting my script over from another client. I have tried defining the Widgets in different parts of my class but they still continue to produce a NullPointer.

    I am defining some of them as: 

    ihml2Qz.png

    Then like this in my execute method:

    kKpL6QO.png

    Now I am using switch cases in my task and this is what the first step looks like and it produces a NP on the first sleepUntil line. My loop return is 800, is this too short? I don't have any errors in the code and I have also tried defining the Widget in this switch case as well.

    case GRAB_BOWL:
                    Settings.state = getState().name();
                    Settings.action = "Searching the cupboard";
                    if (Constants.UTENSIL_CUPBOARD != null && Constants.UTENSIL_CUPBOARD.interact("Search")) {
                        sleepUntil(() -> Widgets.getWidget(242).isVisible(), 1200);
                    }
                    if (bowlWidget != null && bowlWidget.interact("Take-X")) {
                        Settings.action = "Taking some bowls";
                        sleepUntil(enterAmountWidget::isVisible, 2000);
                        if (enterAmountWidget.isVisible()) {
                            Keyboard.type("14", true);
                            sleep(300, 500);
                            sleepUntil(() -> Inventory.contains("Bowl"), 2000);
                            closeButton.interact("Close");
                        sleepUntil(() -> !utensilWidget.isVisible(), 800);
                        }
                    }
                    break;

     

    Link to comment
    Share on other sites

    1 hour ago, LostVirt said:

    null check

    enterAmountWidget

    Thanks, I'll try that but the issue is on the line below

    sleepUntil(() -> Widgets.getWidget(242).isVisible(), 1200);

     

    Link to comment
    Share on other sites

    22 minutes ago, pharaoh said:

    Thanks, I'll try that but the issue is on the line below

    sleepUntil(() -> Widgets.getWidget(242).isVisible(), 1200);

     

    you should be able to do this, for example:
    sleepUntil(() -> Widgets.getWidget(242) != null, 1200);

    But not 100% sure, give it a try :)

    Link to comment
    Share on other sites

    5 hours ago, pharaoh said:

    Thanks, I'll try that but the issue is on the line below

    sleepUntil(() -> Widgets.getWidget(242).isVisible(), 1200);

     

    You need to null check that widget. So you'll do:
    Widgets.getWidget(242) != null && Widgets.getWidget(242).isVisible()

    Link to comment
    Share on other sites

    Java and all the null checks drives me crazy. And optionals would just drive me more crazy. I think maybe I'll just wrap the classes with some null handlers and throw them in a dark corner of my project source window. Then have the log hiccup if there actually is a null. which i don't plan for to be lol.

    Just a tip for you. WATCH out for OnStart. I did something in there. and found out all my problems were solved by moving the code to the OnLoop. Took me 3-4 days to figure out why my onLoop was firing only some of the time.

    Link to comment
    Share on other sites

    On 10/3/2020 at 7:50 PM, Nuclear Nezz said:

    You need to null check that widget. So you'll do:
    Widgets.getWidget(242) != null && Widgets.getWidget(242).isVisible()

    Thanks, I'll do that. 

    member that music fest in like 2015 or something we met up at? cuz i member :drink:

    On 10/4/2020 at 3:30 AM, LordJashin32 said:

    Java and all the null checks drives me crazy. And optionals would just drive me more crazy. I think maybe I'll just wrap the classes with some null handlers and throw them in a dark corner of my project source window. Then have the log hiccup if there actually is a null. which i don't plan for to be lol.

    Just a tip for you. WATCH out for OnStart. I did something in there. and found out all my problems were solved by moving the code to the OnLoop. Took me 3-4 days to figure out why my onLoop was firing only some of the time.

    thanks bro ill be on the lookout haha

    Link to comment
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
     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.