Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Sign up now!

Question Traversal methods giving NullPointerException

Niche bots at your disposal
Joined
Dec 23, 2015
Messages
1,104
Hi there,

I've been having trouble getting my traversal methods up and running. It's very basic code but it won't run for me in any way.

Code:
 @Override
  public void execute()
  {
      determineArea();

      coos = area.getRandomCoordinate();
      System.out.println("Current Coordinates: " + coos); //debug attempt
      final WebPath bp = Traversal.getDefaultWeb().getPathBuilder().buildTo(coos);
     //final BresenhamPath bp = BresenhamPath.buildTo(area.getRandomCoordinate());

      if (bp != null){
          if (bp.step(true)){
              bot.currentTaskString = "Traversing to" + location;
              Execution.delayWhile(Players.getLocal()::isMoving, 1000, 2500);
          }
      }
  }

  void determineArea(){
      if (location == TraversalLocation.cowArea)
      {area = bot.cowArea;}
      else if (location == TraversalLocation.jackoArea)
      {area = bot.jackoArea;}
  }


The error occurs at line "final WebPath bp = Traversal.getDefaultWeb().getPathBuilder().buildTo(coos);" (line 8 in the codefragment)
I tried debugging to see if the coordinates are not recognized but it won't execute anything in the execute function.
This is the log:
Code:
java.lang.NullPointerException
    at com.tyb51.CowCrafter.Leafs.TraversalLeaf.execute(TraversalLeaf.java:37)
    at com.runemate.game.api.script.framework.tree.TreeBot.onLoop(rab:150)
    at com.runemate.game.api.script.framework.LoopingBot.run(zza:221)
    at com.runemate.game.api.script.framework.AbstractBot.start(bcb:61)
    at nul.iiiiIIiIiiII.run(ikb:203)
 
Joined
Aug 23, 2015
Messages
1,970
  • Get rid of final on the webpath
  • Null check area before you use it
  • Null check coos before you use it
  • Add printouts when something is null so that you know it - helps with debugging
Code:
          if (bp.step(true)){
              bot.currentTaskString = "Traversing to" + location;
              Execution.delayWhile(Players.getLocal()::isMoving, 1000, 2500);
          }
  • Will only return true if you took a step that cycle
  • Don't need this delay
  • Look up encapsulation
 
Top