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.

new Bank().open() is causing very strange behaviour. Raising null exception, but it's not null.

Featured Replies

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?

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 by Khaleesi

  • Author

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 by RS13159265

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:

epXNEqD.png

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:

4Nu06jd.png

However there is no need for it, because you can access the already setup instance using `getBank()`.

Edited by Explv

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"

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.