RS13159265 Posted June 5, 2021 Share Posted June 5, 2021 The following code: package MasterScripts; import org.osbot.rs07.api.Bank; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; @ScriptManifest(author="Me", info="NA", logo="", name="TestFunctions", version=1) public class TestFunctions extends Script { @Override public int onLoop() throws InterruptedException { log("Starting script..."); Bank b = new Bank(); log("b is "+b); if (b == null) { log("b is null"); } try { log("Calling b.open()"); b.open(); } catch (Exception e) { log("b.open() generating exception e: "+e); } return 10000; } } Generates Quote [INFO][Bot #1][06/04 09:34:02 PM]: Starting script... [INFO][Bot #1][06/04 09:34:02 PM]: b is org.osbot.rs07.api.Bank@65ebe8f5 [INFO][Bot #1][06/04 09:34:02 PM]: Calling b.open() [INFO][Bot #1][06/04 09:34:02 PM]: b.open() generating exception e: java.lang.NullPointerException [INFO][Bot #1][06/04 09:34:02 PM]: Finishing function What??? As we check, b is a valid pointer, not null. Despite that, calling b.open() generates a NullPointerException. I really have no idea what could be going on. Ideas? Quote Link to comment Share on other sites More sharing options...
Nbacon Posted June 5, 2021 Share Posted June 5, 2021 use a getter Bank b = getBank(); Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted June 5, 2021 Share Posted June 5, 2021 (edited) 3 hours ago, RS13159265 said: The following code: package MasterScripts; import org.osbot.rs07.api.Bank; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; @ScriptManifest(author="Me", info="NA", logo="", name="TestFunctions", version=1) public class TestFunctions extends Script { @Override public int onLoop() throws InterruptedException { log("Starting script..."); Bank b = new Bank(); log("b is "+b); if (b == null) { log("b is null"); } try { log("Calling b.open()"); b.open(); } catch (Exception e) { log("b.open() generating exception e: "+e); } return 10000; } } Generates What??? As we check, b is a valid pointer, not null. Despite that, calling b.open() generates a NullPointerException. I really have no idea what could be going on. Ideas? Just use getBank().open() Edited June 5, 2021 by Khaleesi Quote Link to comment Share on other sites More sharing options...
RS13159265 Posted June 5, 2021 Author Share Posted June 5, 2021 (edited) Thanks. For my understanding: 1) What does new Bank() do / refer to? 2) And, reiterating, why does a non-null object raise a Null exception? Edited June 5, 2021 by RS13159265 Quote Link to comment Share on other sites More sharing options...
Explv Posted June 5, 2021 Share Posted June 5, 2021 (edited) 1 hour ago, RS13159265 said: Thanks. For my understanding: 1) What does new Bank() do / refer to? 2) And, reiterating, why does a non-null object raise a Null exception? 1. You're creating a new instance of the Bank class, this is an OSBot API class which extends MethodProvider. Any class which extends MethodProvider needs to have some context provided, so that it has access to all the other OSBot API class instances (e.g. inventory, equipment, etc.). In your case, you have not provided this context, and so all of these API references are null. You don't *need* to create an instance of the Bank class anyway, because OSBot provides you one that is correctly setup, which you access via getBank(). 2. It is the `open` function throwing a null pointer exception. This means that something the open function is trying to access is null (again because you have not exchanged context, so the internal fields in the Bank class are null) You can see the open function here: On the 4th line of the function you can see `this.inventory.isItemSelected()` `this.inventory` will be null, as you have not exchanged context. Therefore this function call will throw a NullPointerException. This would probably work: Bank bank = new Bank(); bank.exchangeContext(getBot()); exchangeContext sets all the internal context fields in the API class instance using the provided Bot reference. You can see the implementation here: However there is no need for it, because you can access the already setup instance using `getBank()`. Edited June 5, 2021 by Explv 2 Quote Link to comment Share on other sites More sharing options...
RS13159265 Posted June 5, 2021 Author Share Posted June 5, 2021 @Explv ahh that makes sense, thank you very much. How did you manage to get the source code? Quote Link to comment Share on other sites More sharing options...
Explv Posted June 6, 2021 Share Posted June 6, 2021 23 hours ago, RS13159265 said: @Explv ahh that makes sense, thank you very much. How did you manage to get the source code? It's not the true source code, it's just decompiled. You can see it in IntelliJ by right clicking something and selecting "go to > implementations" Quote Link to comment Share on other sites More sharing options...