Welcome!

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

Sign up now!

Resolved What am i doing worng. nullpointerexception in validate()

Joined
Oct 16, 2017
Messages
4
First time trying to make myself a bot.
I am relatively new to Java, and Runemate.

Error message and the files:

java.lang.NullPointerException
at com.Omrudon.bot.Smelter.Branch.oreInInventory.validate(oreInInventory.java:32)
at com.runemate.game.api.script.framework.tree.TreeBot.onLoop(hdc:29)
at com.runemate.game.api.script.framework.LoopingBot.run(rcc:200)
at com.runemate.game.api.script.framework.AbstractBot.start(mbc:8508)
at nul.IIIiIIiiIiiii.run(mmc:154)

Code:
package com.Omrudon.bot.Smelter.Branch;

import com.Omrudon.bot.Smelter.OMBot;
import com.runemate.game.api.hybrid.local.hud.interfaces.Inventory;
import com.runemate.game.api.script.framework.tree.BranchTask;
import com.runemate.game.api.script.framework.tree.TreeTask;

public class oreInInventory extends BranchTask {

    public OMBot omBot;
    public oreInInventory(OMBot omBot) {
        omBot = omBot;
    }
    public portableExists portableExists = new portableExists(omBot);
    public isBankOpen isBankOpen = new isBankOpen(omBot);

    @Override
    public TreeTask failureTask() {
        return isBankOpen;
    }

    @Override
    public TreeTask successTask() {
        return portableExists;
    }

   @Override
    public boolean validate() {
        return Inventory.contains(omBot.Settings.materialName);
    }
}

Code:
package com.Omrudon.bot.Smelter;

import com.Omrudon.Util.AntiBot;
import com.Omrudon.bot.Smelter.Branch.oreInInventory;
import com.runemate.game.api.script.framework.tree.TreeBot;
import com.runemate.game.api.script.framework.tree.TreeTask;

public class OMBot extends TreeBot {

    public Settings Settings = new Settings();
    public AntiBot antiBot = new AntiBot();

    @Override
    public TreeTask createRootTask() {
        return new oreInInventory(this);
    }
}

Code:
package com.Omrudon.bot.Smelter;

public class Settings {
    public final String materialName = <<Some string>>;
    << ++ other variables >>
}
 
Hexis bots go brrr
Joined
Dec 9, 2016
Messages
4,057
You are incorrectly assigning the variable in the constructor of oreInInventory.java. You currently have
Code:
public OMBot omBot;
    public oreInInventory(OMBot omBot) {
        omBot = omBot;
    }
but instead you need
Code:
public OMBot omBot;
    public oreInInventory(OMBot omBot) {
        this.omBot = omBot;
    }

Doing omBot = omBot means you're assigning the variable from the parameter to itself, but not the omBot object from the class. This means the object from the class is null, and then you try to call a method on it, throwing a NullPointerException.
 
Top