Jump to content

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


Recommended Posts

Posted (edited)
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
Posted
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?

Posted

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()

Posted (edited)

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
Posted (edited)
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
Posted
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!

  • Sad 1
Posted
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 :)

Posted
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.

  • Like 1
Posted
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!

Posted (edited)

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
  • Like 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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