Jump to content

Why getting NPE for this trading :(((


Recommended Posts

Posted
            case TRADE:
                Player muler = getPlayers().closest(player -> player != null && player.getName().equals(mule));
                if (!trade.isCurrentlyTrading()) {
                    state = "Trading with mule.";
                    muler.interact("Trade with");
                    new org.osbot.rs07.utility.ConditionalSleep(20000) {
                        @Override
                        public boolean condition() throws InterruptedException {
                            return trade.isCurrentlyTrading();
                        }
                    }.sleep();
                }

why getting null pointer exception for this? :(

Posted

You should still do a null check for the muler object.

if(muler != null) {
	// then we can access the muler object
}

Also when you use an Interactable the method returns a boolean so you should check if your .interact() interaction returns true.

Player muler = getPlayers().closest(player -> player != null && player.getName().equals(mule));
if(muler != null) {
    if(!trade.isCurrentlyTrading()) {
        if(muler.interact("Trade with")) {
            state = "Trading with mule.";
            // sleep condition
        }
    }
}

 

  • Like 1

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
  • Recently Browsing   0 members

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