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.

" Error in script executor! java.lang.NullPointerException " when trying to start a script, what could be wrong? :)

Featured Replies

Getting 

Error in script executor!
java.lang.NullPointerException

when trying to start a script. What could be wrong? :o 

  • Author
3 minutes ago, FuryShark said:

Is this happening with every script or a specific script?

Happening everytime I start this script i made ; 

 

public class EdgeSmelter extends Script {

    private Area smeltArea = new Area(3105, 3501, 3110, 3496);

    private void bronzeBars(){

        boolean gotCopperAndTinOre = getInventory().contains("Copper ore", "Tin ore");
        boolean isSmeltScreenVisible = getWidgets().get(270,14).isVisible();
        boolean inSmeltArea = smeltArea.contains(myPosition());

        RS2Widget bronzeBarsButton = getWidgets().get(270,14);
        RS2Object smelter = getObjects().closest("Furnace");

        if (gotCopperAndTinOre && !inSmeltArea){

            log("Walking to Smelter");
            getWalking().webWalk(smeltArea);
        }

        if (inSmeltArea && smelter != null) {

            smelter.interact("Smelt");
            SleepEasy.sleepUntil(() -> isSmeltScreenVisible, 5000);

            bronzeBarsButton.interact("Smelt");
            SleepEasy.sleepUntil(() -> !gotCopperAndTinOre,18000);
        }
    }

    private void needToBank() throws InterruptedException {

        boolean gotCopperAndTinOre = getInventory().contains("Copper ore", "Tin ore");

       if (!Banks.EDGEVILLE.contains(myPosition()) && !gotCopperAndTinOre){

            log("Walking to bank");
            getWalking().webWalk(Banks.EDGEVILLE);
        }

       if (Banks.EDGEVILLE.contains(myPosition()) && !gotCopperAndTinOre) {

           getBank().open();
           SleepEasy.sleepUntil(() -> getBank().isOpen(), 10000);
           log("Depositing bronze bars");
           getBank().depositAll("Bronze bar");

           log("Withdrawing ores");
           getBank().withdraw("Copper ore" + "Tin ore", 14);
       }

       if (!getBank().contains("Copper ore", "Tin ore")){
           log("Stopping script");
               stop(false);
       }

    }


    @Override
    public int onLoop() throws InterruptedException{

        boolean gotCopperAndTinOre = getInventory().contains("Copper ore", "Tin ore");

        if (!gotCopperAndTinOre) {

            needToBank();

        } else {

            bronzeBars();
        }


        return 600;
    }
}

What did I do wrong? :o 

Edited by t0r3

8 minutes ago, t0r3 said:

Happening everytime I start this script i made ; 

 


public class EdgeSmelter extends Script {

    private Area smeltArea = new Area(3105, 3501, 3110, 3496);

    private void bronzeBars(){

        boolean gotCopperAndTinOre = getInventory().contains("Copper ore", "Tin ore");
        boolean isSmeltScreenVisible = getWidgets().get(270,14).isVisible();
        boolean inSmeltArea = smeltArea.contains(myPosition());

        RS2Widget bronzeBarsButton = getWidgets().get(270,14);
        RS2Object smelter = getObjects().closest("Furnace");

        if (gotCopperAndTinOre && !inSmeltArea){

            log("Walking to Smelter");
            getWalking().webWalk(smeltArea);
        }

        if (inSmeltArea && smelter != null) {

            smelter.interact("Smelt");
            SleepEasy.sleepUntil(() -> isSmeltScreenVisible, 5000);

            bronzeBarsButton.interact("Smelt");
            SleepEasy.sleepUntil(() -> !gotCopperAndTinOre,18000);
        }
    }

    private void needToBank() throws InterruptedException {

        boolean gotCopperAndTinOre = getInventory().contains("Copper ore", "Tin ore");

       if (!Banks.EDGEVILLE.contains(myPosition()) && !gotCopperAndTinOre){

            log("Walking to bank");
            getWalking().webWalk(Banks.EDGEVILLE);
        }

       if (Banks.EDGEVILLE.contains(myPosition()) && !gotCopperAndTinOre) {

           getBank().open();
           SleepEasy.sleepUntil(() -> getBank().isOpen(), 10000);
           log("Depositing bronze bars");
           getBank().depositAll("Bronze bar");

           log("Withdrawing ores");
           getBank().withdraw("Copper ore" + "Tin ore", 14);
       }

       if (!getBank().contains("Copper ore", "Tin ore")){
           log("Stopping script");
               stop(false);
       }

    }


    @Override
    public int onLoop() throws InterruptedException{

        boolean gotCopperAndTinOre = getInventory().contains("Copper ore", "Tin ore");

        if (!gotCopperAndTinOre) {

            needToBank();

        } else {

            bronzeBars();
        }


        return 600;
    }
}

What did I do wrong? :o 

Is that the entire script? and does the NPE direct you to any line?

None of these variables update more than once (at the start), and are probably causing the NPE.

        boolean gotCopperAndTinOre = getInventory().contains("Copper ore", "Tin ore");
        boolean isSmeltScreenVisible = getWidgets().get(270,14).isVisible();
        boolean inSmeltArea = smeltArea.contains(myPosition());

        RS2Widget bronzeBarsButton = getWidgets().get(270,14);
        RS2Object smelter = getObjects().closest("Furnace");

You'll want to have a function for each.

Also, you need to check for !null before .isVisible()

  • Author

ok, changed it to this; which is my whole script (minus SleepEasy class) :o Still not working

 

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.map.constants.Banks;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.api.ui.RS2Widget;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import sleep.SleepEasy;


@ScriptManifest(author = "t0r3", name = "EdgeSmelter", info = "", version = 0.1, logo = "")

public class EdgeSmelter extends Script {

    private Area smeltArea = new Area(3105, 3501, 3110, 3496);

    private void bronzeBars(){

        boolean gotCopperAndTinOre = getInventory().contains("Copper ore", "Tin ore");
        boolean bronzeButtonExists = getWidgets().get(270,14) != null;
        boolean isSmeltScreenVisible = getWidgets().get(270,14).isVisible();
        boolean inSmeltArea = smeltArea.contains(myPosition());

        RS2Widget bronzeBarsButton = getWidgets().get(270,14);
        RS2Object smelter = getObjects().closest("Furnace");

        if (!inSmeltArea){

            log("Walking to Smelter");
            getWalking().webWalk(smeltArea);
            SleepEasy.sleepUntil(() -> inSmeltArea, 18000);
        }

        if (inSmeltArea && smelter != null) {

            smelter.interact("Smelt");
            SleepEasy.sleepUntil(() -> isSmeltScreenVisible, 5000);

            if (bronzeButtonExists && isSmeltScreenVisible) {

                bronzeBarsButton.interact("Smelt");
                SleepEasy.sleepUntil(() -> !gotCopperAndTinOre, 18000);
            }
        }
    }

    private void needToBank() throws InterruptedException {

        boolean gotCopperAndTinOre = getInventory().contains("Copper ore", "Tin ore");

       if (!Banks.EDGEVILLE.contains(myPosition())){

            log("Walking to bank");
            getWalking().webWalk(Banks.EDGEVILLE);
            SleepEasy.sleepUntil(() -> Banks.EDGEVILLE.contains(myPosition()),18000);
        }

       if (Banks.EDGEVILLE.contains(myPosition()) && !getBank().open()) {

           getBank().open();
           SleepEasy.sleepUntil(() -> getBank().isOpen(), 10000);

           if (getBank().isOpen()) {
               log("Depositing bronze bars");
               getBank().depositAll("Bronze bar");
               SleepEasy.sleepUntil(() -> getInventory().isEmpty(),500);

               if (getInventory().isEmpty()) {

                   log("Withdrawing ores");
                   getBank().withdraw("Copper ore", 14);
                   getBank().withdraw("Tin ore", 14);
                   SleepEasy.sleepUntil(() -> gotCopperAndTinOre, 500);
               }
           }
       }

       if (!getBank().contains("Copper ore", "Tin ore")){
           log("Stopping script");
           stop(false);
       }
    }

    @Override
    public int onLoop() throws InterruptedException{

        boolean gotCopperAndTinOre = getInventory().contains("Copper ore", "Tin ore");

        if (!gotCopperAndTinOre && !Banks.EDGEVILLE.contains(myPosition())) {

            needToBank();
        }

        if (gotCopperAndTinOre && gotCopperAndTinOre){

            bronzeBars();
        }


        return 600;
    }
}

Edited by t0r3

  • Author
26 minutes ago, HeyImJamie said:

Show the god damn NPE. ?

Can't even interact with the logger hahah?  Goes completely potato

Might just have to write the script from scratch again

Edited by t0r3

  • Author
33 minutes ago, HeyImJamie said:

Show the god damn NPE. ?

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.map.constants.Banks;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.api.ui.RS2Widget;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import sleep.SleepEasy;


@ScriptManifest(author = "t0r3", name = "EdgeSmelter", info = "Sleep", version = 0.1, logo = "")

public class EdgeSmelter extends Script {

    private Area smeltArea = new Area(3105, 3501, 3110, 3496);

    private void bronzeBars(){

        boolean gotCopperAndTinOre = getInventory().contains("Copper ore", "Tin ore");

        RS2Widget bronzeBarsButton = getWidgets().get(270,14);
        RS2Object smelter = getObjects().closest("Furnace");

        if (!smeltArea.contains(myPosition())){

            log("Walking to Smelter");
            getWalking().webWalk(smeltArea);
            SleepEasy.sleepUntil(() -> smeltArea.contains(myPosition()), 18000);
        }

        if (smeltArea.contains(myPosition()) && smelter != null) {

            boolean bronzeButtonExists = getWidgets().get(270,14) != null;
            boolean isSmeltScreenVisible = getWidgets().get(270,14).isVisible();

            smelter.interact("Smelt");
            SleepEasy.sleepUntil(() -> isSmeltScreenVisible, 5000);

            if (bronzeButtonExists && isSmeltScreenVisible) {

                bronzeBarsButton.interact("Smelt");
                SleepEasy.sleepUntil(() -> !gotCopperAndTinOre, 18000);
            }
        }
    }

    private void needToBank() throws InterruptedException {

       if (!Banks.EDGEVILLE.contains(myPosition())){

            log("Walking to bank");
            getWalking().webWalk(Banks.EDGEVILLE);
            SleepEasy.sleepUntil(() -> Banks.EDGEVILLE.contains(myPosition()),18000);
        }

       if (Banks.EDGEVILLE.contains(myPosition()) && !getBank().open()) {

           getBank().open();
           SleepEasy.sleepUntil(() -> getBank().isOpen(), 10000);

           if (getBank().isOpen()) {
               log("Depositing bronze bars");
               getBank().depositAll("Bronze bar");
               SleepEasy.sleepUntil(() -> getInventory().isEmpty(),500);

               if (getInventory().isEmpty()) {

                   boolean gotCopperAndTinOre = getInventory().contains("Copper ore", "Tin ore");

                   log("Withdrawing ores");
                   getBank().withdraw("Copper ore", 14);
                   getBank().withdraw("Tin ore", 14);
                   SleepEasy.sleepUntil(() -> gotCopperAndTinOre, 500);
               }
           }
       }
    }

    @Override
    public int onLoop() throws InterruptedException{

        boolean gotCopperAndTinOre = getInventory().contains("Copper ore", "Tin ore");

        if (!getInventory().contains("Copper ore", "Tin ore") && !Banks.EDGEVILLE.contains(myPosition())) {

            needToBank();
        }

        if (getInventory().contains("Copper ore", "Tin ore")){

            bronzeBars();
        }


        return 600;
    }
}

Ok, changed the script to this above, and got this NPE ;

Error in script executor!
java.lang.NullPointerException
    at EdgeSmelter.bronzeBars(EdgeSmelter.java:33)
    at EdgeSmelter.onLoop(EdgeSmelter.java:90)
    at org.osbot.rs07.event.ScriptExecutor$InternalExecutor.run(df:126)
    at java.lang.Thread.run(Unknown Source)

Edited by t0r3

7 minutes ago, t0r3 said:


 

Ok, changed the script to this above, and got this NPE ;

Error in script executor!
java.lang.NullPointerException
    at EdgeSmelter.bronzeBars(EdgeSmelter.java:33)
    at EdgeSmelter.onLoop(EdgeSmelter.java:90)
    at org.osbot.rs07.event.ScriptExecutor$InternalExecutor.run(df:126)
    at java.lang.Thread.run(Unknown Source)

I don't think spoonfeeding you here is going to help you much. The NPE directs you to where the error is (line 33 of your script). You're not null checking something correctly on that line, so go figure it out :D Based on looking at your code though there's a few areas where you haven't bothered to null check, so get them fixed up too and you'll be good to go!

  • Author
7 minutes ago, HeyImJamie said:

I don't think spoonfeeding you here is going to help you much. The NPE directs you to where the error is (line 33 of your script). You're not null checking something correctly on that line, so go figure it out :D Based on looking at your code though there's a few areas where you haven't bothered to null check, so get them fixed up too and you'll be good to go!

Yeah u'r right ahha :D Managed to fix it :) I'll b careful to null check in the future. Ty :)

Just now, t0r3 said:

Yeah u'r right ahha :D Managed to fix it :) I'll b careful to null check in the future. Ty :)

Well done :D Next step I'd say would be to re-think your logic a little bit. For example, your bank method could be re-ordered so it checks that the bank contains the ore prior to withdrawing, rather than attempting to withdraw and then stopping script.

55 minutes ago, t0r3 said:

smelter.interact("Smelt");

SleepEasy.sleepUntil(() -> isSmeltScreenVisible, 5000);

Another thing you can do is changing these to
 

if (smelter.interact("Smelt")) {
Sleep.... 


so that it doesnt sleep if it fails to interact

  • Author
2 hours ago, HeyImJamie said:

Well done :D Next step I'd say would be to re-think your logic a little bit. For example, your bank method could be re-ordered so it checks that the bank contains the ore prior to withdrawing, rather than attempting to withdraw and then stopping script.

Good point :D Rearranged it, thanks!

1 hour ago, FuryShark said:

Another thing you can do is changing these to
 

if (smelter.interact("Smelt")) {
Sleep.... 


so that it doesnt sleep if it fails to interact

Yeah I should probably do that :) Thank you!

I see you have a 2 declarations for the bronze bar button. One for null checking and another for interacting. You can just use the interacting declaration and null check that instead

RS2Widget bronzeBarsButton = getWidgets().get(270,14);

if (bronzeBarsButton != null && bronzeBarsButton.isVisible(){
	bronzeBarsButton.interact("smelt")
	
	//your sleep

}

Edit: Just an FYI too, you don't need a sleep for webwalking. I did the same thing when I first started off too, but then realized its not going to continue reading lines until webwalking is done

Edited by Dab in a Lab

Create an account or sign in to comment

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.