t0r3 Posted April 1, 2019 Share Posted April 1, 2019 Getting Error in script executor! java.lang.NullPointerException when trying to start a script. What could be wrong? Quote Link to comment Share on other sites More sharing options...
FuryShark Posted April 1, 2019 Share Posted April 1, 2019 Is this happening with every script or a specific script? Quote Link to comment Share on other sites More sharing options...
t0r3 Posted April 1, 2019 Author Share Posted April 1, 2019 (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? Edited April 1, 2019 by t0r3 Quote Link to comment Share on other sites More sharing options...
HeyImJamie Posted April 1, 2019 Share Posted April 1, 2019 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? Is that the entire script? and does the NPE direct you to any line? Quote Link to comment Share on other sites More sharing options...
Naked Posted April 1, 2019 Share Posted April 1, 2019 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() Quote Link to comment Share on other sites More sharing options...
t0r3 Posted April 1, 2019 Author Share Posted April 1, 2019 (edited) ok, changed it to this; which is my whole script (minus SleepEasy class) 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 April 1, 2019 by t0r3 Quote Link to comment Share on other sites More sharing options...
HeyImJamie Posted April 1, 2019 Share Posted April 1, 2019 Show the god damn NPE. Quote Link to comment Share on other sites More sharing options...
t0r3 Posted April 1, 2019 Author Share Posted April 1, 2019 (edited) 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 April 1, 2019 by t0r3 Quote Link to comment Share on other sites More sharing options...
t0r3 Posted April 1, 2019 Author Share Posted April 1, 2019 (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 April 1, 2019 by t0r3 Quote Link to comment Share on other sites More sharing options...
HeyImJamie Posted April 1, 2019 Share Posted April 1, 2019 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 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! 1 Quote Link to comment Share on other sites More sharing options...
t0r3 Posted April 1, 2019 Author Share Posted April 1, 2019 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 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 Managed to fix it I'll b careful to null check in the future. Ty Quote Link to comment Share on other sites More sharing options...
HeyImJamie Posted April 1, 2019 Share Posted April 1, 2019 Just now, t0r3 said: Yeah u'r right ahha Managed to fix it I'll b careful to null check in the future. Ty Well done 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. 1 Quote Link to comment Share on other sites More sharing options...
FuryShark Posted April 1, 2019 Share Posted April 1, 2019 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 1 Quote Link to comment Share on other sites More sharing options...
t0r3 Posted April 1, 2019 Author Share Posted April 1, 2019 2 hours ago, HeyImJamie said: Well done 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 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! Quote Link to comment Share on other sites More sharing options...
Dab in a Lab Posted April 2, 2019 Share Posted April 2, 2019 (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 April 2, 2019 by Dab in a Lab 1 Quote Link to comment Share on other sites More sharing options...