Jump to content

Null pointer Exception when executing a webwalkevent


redgar72

Recommended Posts

Here is a walk function I made, the error occurs on the execute(walkEvent) line.

public void walk(Area area) throws InterruptedException{
        WebWalkEvent walkEvent = new WebWalkEvent(area);
        execute(walkEvent);
        while (!area.contains(myPlayer().getPosition())) {
            Thread.sleep(1000);
        }
    }

 

This is called like this: walk(new Area(3189, 3273, 3189, 3272));

 

Does anyone know what is wrong with this function that would be causing it to throw a null pointer exception?

 

 

 

 

Link to comment
Share on other sites

Not sure why it would be throwing an NPE, usually this happens when someone calls the wrong execute function, which you are not.

Bit of a tip as well, that while loop is going to do nothing as it wont start until the webwalk event has finished.

 

Could you paste the entire exception? 

Edited by Tom
Link to comment
Share on other sites

1 hour ago, Tom said:

Not sure why it would be throwing an NPE, usually this happens when someone calls the wrong execute function, which you are not.

Bit of a tip as well, that while loop is going to do nothing as it wont start until the webwalk event has finished.

 

Could you paste the entire exception? 

The reason I have that loop there was for testing purposes because in a previous iteration I had a web walk event that led into a NPC interaction and the bot would try to interact with the NPC as it was walking before it got to the actual area and opened the door before the npc

Link to comment
Share on other sites

58 minutes ago, Malcolm said:

This probably could throw an NPE if you have this in a separate class and don’t extend method provider in that class and exchange context. Although this should be pretty obvious as your IDE should highlight that for you as an error 

You don’t need to remove the parameter. You’d just call it like you have. Alternatively you could make a variable for your area and call walk(variable); 

My walk function is in a separate class that does extend the Method Provider. 

1 hour ago, Tom said:

Not sure why it would be throwing an NPE, usually this happens when someone calls the wrong execute function, which you are not.

Bit of a tip as well, that while loop is going to do nothing as it wont start until the webwalk event has finished.

 

Could you paste the entire exception? 

image.png.425aa01084c62df12f7b82704e106de6.png

Osbot crashes as this is running so I can not copy paste, However here is a screenshot.

Link to comment
Share on other sites

1 hour ago, redgar72 said:

My walk function is in a separate class that does extend the Method Provider. 

image.png.425aa01084c62df12f7b82704e106de6.png

Osbot crashes as this is running so I can not copy paste, However here is a screenshot.

Can you provide a copy of all of your script or at least up to where the error is occurring (line 62). You can pm me if you don't want to share it publicly.

Also, I'm not sure why you included the sleep part. If a WebWalk event fails, you might as well just have it log out rather than constantly sleeping till it logs out anyways. There's definitely a better way to do whatever you are trying to do, but I would need to see the context. You can also check if a webWalk event is able to be completed before you even start walking. 

 public boolean canWalk(Area area) {
        WebWalkEvent w = new WebWalkEvent(area);
        return w.prefetchRequirements(this);
    }

This will return true if a destination is found and directions are created. In which case, there's really no reason it wouldn't reach the destination.

Link to comment
Share on other sites

8 hours ago, redgar72 said:

My walk function is in a separate class that does extend the Method Provider. 

image.png.425aa01084c62df12f7b82704e106de6.png

Osbot crashes as this is running so I can not copy paste, However here is a screenshot.

If its in a different class, you need to either exchange context, or not extend method provider and use dependency injection instead, like so

void walk(Script instance, Area area){

    WebWalkEvent e = new WebWalkEvent(area);
    instance.execute(e);
 

}

Link to comment
Share on other sites

11 hours ago, Tom said:

If its in a different class, you need to either exchange context, or not extend method provider and use dependency injection instead, like so

void walk(Script instance, Area area){

    WebWalkEvent e = new WebWalkEvent(area);
    instance.execute(e);
 

}

I merged the two classes and I am still getting a NPE at the same line

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...