Jump to content
Jack

Null pointers

Recommended Posts

[ERROR][Bot #1][07/02 07:31:01 PM]: Error in script executor!
java.lang.NullPointerException
	at org.osbot.utility.Logger.log(f:243)
	at org.osbot.utility.Logger.log(f:189)
	at org.osbot.utility.Logger.log(f:25)
	at org.osbot.utility.Logger.info(f:4)
	at org.osbot.rs07.script.MethodProvider.log(MethodProvider.java:721)
	at net.jack.scripts.Core.onLoop(Core.java:111)
	at org.osbot.rs07.event.ScriptExecutor$InternalExecutor.run(ScriptExecutor.java:99)
	at java.lang.Thread.run(Unknown Source)

was there an error on line 111? This is line 111:

catch(Exception e){
--->    log(e.getMessage());
}

So what was the original error? Did it throw an exception while trying to tell me what the previous exception was? Im so confused huh.png

Edited by Jack
Link to comment
Share on other sites

[ERROR][Bot #1][07/02 07:31:01 PM]: Error in script executor!
java.lang.NullPointerException
	at org.osbot.utility.Logger.log(f:243)
	at org.osbot.utility.Logger.log(f:189)
	at org.osbot.utility.Logger.log(f:25)
	at org.osbot.utility.Logger.info(f:4)
	at org.osbot.rs07.script.MethodProvider.log(MethodProvider.java:721)
	at net.jack.scripts.Core.onLoop(Core.java:111)
	at org.osbot.rs07.event.ScriptExecutor$InternalExecutor.run(ScriptExecutor.java:99)
	at java.lang.Thread.run(Unknown Source)

was there an error on line 111? This is line 111:

catch(Exception e){
--->    log(e.getMessage());
}

So what was the original error? Did it throw an exception while trying to tell me what the previous exception was? Im so confused huh.png

 

 

Its possible that something is crapping out and killing or messing up the script executor. If this happens then the client would throw an NPE because there would be no script to log to, because log is actually in Script#log(). If script doesnt exist, then you cant log. Thus the NPE on the log method. Just delete that log and do e.printStackTrace() instead. ^_^

 

What is inside of your try{} that could throw an exception?

Link to comment
Share on other sites

Its possible that something is crapping out and killing or messing up the script executor. If this happens then the client would throw an NPE because there would be no script to log to, because log is actually in Script#log(). If script doesnt exist, then you cant log. Thus the NPE on the log method. Just delete that log and do e.printStackTrace() instead. happy.png

 

What is inside of your try{} that could throw an exception?

Mostly sleeps and a few npc interactions

 

I think it was client error though, not script error.

Link to comment
Share on other sites

Is Core your main script, or is another class your main script and you're passing the script reference to Core? Because if you are then it should be script.log, if your reference is called script.

Core is my main class that extends script

 

It seems to now be working when I added a null check here: (food is an ArrayList<String> of food names)

for(int i = 0; i < inventory.getItems().length; i++){
			if(inventory.getItems()[i]!=null&&food.contains(inventory.getItems()[i].getName())){
				inventory.getItems()[i].interact("Eat");
				return random(650, 900);
			}
		}

Is there a better way to write this?

Link to comment
Share on other sites

Core is my main class that extends script

 

It seems to now be working when I added a null check here: (food is an ArrayList<String> of food names)

for(int i = 0; i < inventory.getItems().length; i++){
			if(inventory.getItems()[i]!=null&&food.contains(inventory.getItems()[i].getName())){
				inventory.getItems()[i].interact("Eat");
				return random(650, 900);
			}
		}

Is there a better way to write this?

 

This is my method for eating food, it might need a small change or two, but I have not yet had an issues with it, nor an exception thrown from it. It seems that you forgot to make sure the inventory tab is open. You cant interact with the food if your inventory tab isn't open. 

    public boolean eatFood(String foodName){
        Item food = script.inventory.getItem(foodName);
        if(food != null && script.inventory.contains(foodName)){
            if(script.tabs.getOpen().equals(Tab.INVENTORY))
                return food.interact("Eat");
            else
                script.tabs.open(Tab.INVENTORY);
        }
        return false;
    }

happy.png

Edited by Mysteryy
Link to comment
Share on other sites

Core is my main class that extends script

 

It seems to now be working when I added a null check here: (food is an ArrayList<String> of food names)

for(int i = 0; i < inventory.getItems().length; i++){
			if(inventory.getItems()[i]!=null&&food.contains(inventory.getItems()[i].getName())){
				inventory.getItems()[i].interact("Eat");
				return random(650, 900);
			}
		}

Is there a better way to write this?

you could always use a enhanced for loop

for (Item item: script.inventory.getItems()) {
     if (item != null && item.getName().equalsIgnoreCase(argument)) {
       blah blah
     }
}
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...