Jump to content

NullPointer when using MethodProvider in other classes


Recommended Posts

Posted (edited)

I'm writing a sand crab bot and currently writing the logic for checking what spots are available.

I've been debugging a null pointer problem I've been getting and it looks like whenever I try and use a method from the MethodProvider class (currently trying log) I get a null pointer.

Create an instance of SpotManager passing the RIFTSandCrabs class (my script) ,,,

public class RIFTSandCrabs extends Script {
	
	...
	
	private SpotManager spotManager = new SpotManager(this);

And then in my SpotManager I have this ...

public class SpotManager extends MethodProvider {
	
	...

	private Script RIFTSandCrabs;
	
	public SpotManager(Script RIFTSandCrabs) {
		this.RIFTSandCrabs = RIFTSandCrabs;
	}
	
	...
	
	private void updatePositions() {
		for (int i = 0; i < crabLocations.length; i++ ) {
			log(i);
			updatePosition(crabLocations[i], i);
		}
	}
	
	private void updatePosition(Position p, int index) {
		RIFTSandCrabs.stop(false);
		log("Position coords are " + p.toString());
		log("Players located are " + getPlayers());
		log("Result of isEmpty() is " + getPlayers().get(p.getX(), p.getY()).isEmpty());
		
		if (getPlayers().get(p.getX(), p.getY()).isEmpty()) {
			spotStatus[index] = true;
		}
	}
	
	...
                                                 
}

I pass the instance of my script through to this class only to stop executing at a certain point to check logs etc.

What I'm trying to do is make sure the logic I have in place to check if a spot is free is correct and is returning what I want it to return. I get a null pointer at " log(i) " inside the for loop of updatePositions( ).

I'm a Java nooblet, so any help would be appreciated

EDIT:

Solved problem. Resource was in Explvs Tutorial (5).

Close please

Edited by R I F T
Solved

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...