Jump to content

NullPointer when using MethodProvider in other classes


R I F T

Recommended Posts

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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