Jump to content

Creating wrapper?


Swizzbeat

Recommended Posts

I'm creating wrapper classes for some stuff, however it seems that for this one at least I'm getting an NPE when I check for whether it exists or not. Here's the (unfinished) wrapper class:

package core.utils.wrappers;

import org.osbot.accessor.XGroundItem;
import org.osbot.script.Script;
import org.osbot.script.rs2.model.GroundItem;

/**
 * Created with IntelliJ IDEA
 * User: Anthony
 * Date: 5/13/2014
 */

public class Loot extends GroundItem {

	private XGroundItem instance;
	private Script sI;

	public Loot(XGroundItem instance, Script sI) {
		super(instance);
		this.instance = instance;
		this.sI = sI;
	}

	public void pickUp(boolean loopUntilPickedUp) throws InterruptedException {
		do {
			interact("Take");
		}
		while (loopUntilPickedUp && exists());
	}

	public XGroundItem getInstance() {
		return instance;
	}

}

The part where I am getting the NPE is when I declare an object of type Loot and call the #exists() method (could be an issue for other methods but I haven't got past this one yet). I declare the object in a similar fashion to this:

Loot loot = new Loot(closestGroundItemForName("whatever").instance, sI);

The error message is then logged to the console:

[ERROR][05/14/14 08:10:52 AM]: Error on executing script worker!
java.lang.NullPointerException
	at org.osbot.script.rs2.model.GroundItem.getZ(zf:147)
	at org.osbot.script.rs2.map.Region.contains(dg:154)
	at org.osbot.script.rs2.model.GroundItem.exists(zf:84)
	at core.tasks.Looter.execute(Looter.java:41)
	at core.task_framework.TaskManager.findAndExecuteTaskInCategory(TaskManager.java:22)
	at core.Main.onLoop(Main.java:133)
	at org.osbot.hc.run(um:136)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)

Any help would be appreciated. I feel like I'm doing something incredibly stupid O_o

 

 

FYI my other wrapper classes work fine.

Edited by Swizzbeat
Link to comment
Share on other sites

I'm creating wrapper classes for some stuff, however it seems that for this one at least I'm getting an NPE when I check for whether it exists or not. Here's the (unfinished) wrapper class:

package core.utils.wrappers;

import org.osbot.accessor.XGroundItem;
import org.osbot.script.Script;
import org.osbot.script.rs2.model.GroundItem;

/**
 * Created with IntelliJ IDEA
 * User: Anthony
 * Date: 5/13/2014
 */

public class Loot extends GroundItem {

	private XGroundItem instance;
	private Script sI;

	public Loot(XGroundItem instance, Script sI) {
		super(instance);
		this.instance = instance;
		this.sI = sI;
	}

	public void pickUp(boolean loopUntilPickedUp) throws InterruptedException {
		do {
			interact("Take");
		}
		while (loopUntilPickedUp && exists());
	}

	public XGroundItem getInstance() {
		return instance;
	}

}

The part where I am getting the NPE is when I declare an object of type Loot and call the #exists() method (could be an issue for other methods but I haven't got past this one yet). I declare the object in a similar fashion to this:

Loot loot = new Loot(closestGroundItemForName("whatever").instance, sI);

The error message is then logged to the console:

[ERROR][05/14/14 08:10:52 AM]: Error on executing script worker!
java.lang.NullPointerException
	at org.osbot.script.rs2.model.GroundItem.getZ(zf:147)
	at org.osbot.script.rs2.map.Region.contains(dg:154)
	at org.osbot.script.rs2.model.GroundItem.exists(zf:84)
	at core.tasks.Looter.execute(Looter.java:41)
	at core.task_framework.TaskManager.findAndExecuteTaskInCategory(TaskManager.java:22)
	at core.Main.onLoop(Main.java:133)
	at org.osbot.hc.run(um:136)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)

Any help would be appreciated. I feel like I'm doing something incredibly stupid O_o

 

 

FYI my other wrapper classes work fine.

 

Silly Swizz <3 you can't call interact like that (interact("Take")), because that would try to call the interact method inherited from GroundItem, which will try to use some instance variables inherited from GroundItem, which are null because you never set them up (for example the position of the item).

 

Try casting instance and then calling interact on that... ((GroundItem)instance).interact("Take");

Edited by ericthecmh
Link to comment
Share on other sites

Silly Swizz <3 you can't call interact like that (interact("Take")), because that would try to call the interact method inherited from GroundItem, which will try to use some instance variables inherited from GroundItem, which are null because you never set them up (for example the position of the item).

Try casting instance and then calling interact on that... ((GroundItem)instance).interact("Take");

But I do, hence the super call passing the instance :p
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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