- Joined
- Mar 23, 2018
- Messages
- 4
- Thread Author
- #1
Hello everyone. I am currently coding a bot that will calculate the players wealth but am stumped by this bug that keeps occuring.
Keeps being thrown after a certain amount of iterations each time I run the bot. I don't understand why it successfully calculates the players inventory until a random point where it throws this NPE, even after null checking it. Am I missing something here?
Here's the relevant code:
Code:
java.lang.NullPointerException
at com.forgottenape101.bots.WealthWatcher.tasks.Calculate.execute(Calculate.java:49)
at com.runemate.game.api.script.framework.task.TaskBot.onLoop(kub:122)
at com.runemate.game.api.script.framework.LoopingBot.run(hub:52)
at com.runemate.game.api.script.framework.AbstractBot.start(zvb:10985)
at nul.IIIiIIiiIIiiI.run(thc:26)
Keeps being thrown after a certain amount of iterations each time I run the bot. I don't understand why it successfully calculates the players inventory until a random point where it throws this NPE, even after null checking it. Am I missing something here?
Here's the relevant code:
Code:
package com.forgottenape101.bots.WealthWatcher.tasks;
import com.runemate.game.api.hybrid.entities.GameObject;
import com.runemate.game.api.hybrid.local.Camera;
import com.runemate.game.api.hybrid.local.hud.interfaces.Bank;
import com.runemate.game.api.hybrid.local.hud.interfaces.SpriteItem;
import com.runemate.game.api.hybrid.net.GrandExchange;
import com.runemate.game.api.hybrid.region.GameObjects;
import com.runemate.game.api.script.Execution;
import com.runemate.game.api.script.framework.task.Task;
public class Calculate extends Task {
@Override
public void execute() {
GameObject booth = GameObjects.newQuery().names("Bank booth").actions("Bank").results().nearest();
long wealth = 0;
if(booth != null){
if(!booth.isVisible()){
System.out.println("Turning to see booth");
Camera.turnTo(booth);
Execution.delayUntil(()->booth.isVisible(), 200, 400);
}
if(Bank.open()){
SpriteItem[] items = Bank.getItems().toArray(new SpriteItem[77]);
if(items != null){
System.out.println("Total Items to Count: " + items.length);
for(int i = 0; i < items.length; i++){
int id = items[i].getId();
if(id != 0){
int q = Bank.getQuantity(id);
if(GrandExchange.lookup(id) != null) {
System.out.println("Looking up price for "+q+"x " + GrandExchange.lookup(id).getName());
int addwealth = GrandExchange.lookup(id).getPrice() * q;
wealth += addwealth;
System.out.println("Total Wealth: " + wealth);
}else{
System.out.println("Could not retreive info, moving to next item.");
}
}
}
}
}
}
}
@Override
public boolean validate() {
return GameObjects.newQuery().names("Bank booth") != null;
}
}