Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Null pointers

Featured Replies

[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

Since the top of the stack points to an error within Logger's log method, I would guess that the logger is unable to change that message to a string? Try logging a test string instead of e.getMessage().

[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?

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.

  • Author

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.

Mostly sleeps and a few npc interactions

 

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

 

 

Ok. Also, look what eric said. Are you passing script to this class? Because if so it needs to be script.log() not log. ^_^

  • Author

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?

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

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
     }
}
Guest
This topic is now closed to further replies.

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.