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.

Getting NullPointerException which points to a file that doesn't exist

Featured Replies

Outside of your question, this is not how you should go on and write this code. What you are trying is to do one method call which results in buying items, without any kind of looping. That's not going to work properly and even if it will, it's unreliable. You can do multiple things. Create an Event class and execute it as an event, let your script loop through it (by using a task system for example) or write a recursive method (not sure if that's a good idea though).

This is an example with an event. When you want to buy items, you will create a new event, pass through the list of items and execute the buying. If you are done buying, you set the event to finished and the script will start looping again. (Not sure if this code works and if it's 100% correct, long time ago for me).

public class Main extends Script {
    
    
    @Override
    public int onLoop() throws InterruptedException {
        if (shouldbuyItems()) {
            BuyItemsEvent event = new BuyItemsEvent(buyItemList);
            event.exchangeContext(getBot());
            execute(event);
        }
        return 300;
    }
}

public class BuyItemsEvent extends Event {
    
    private List<BuyItem> items;
    
    public BuyItemsEvent(List<BuyItem> items) {
        this.items = items;
    }
    
    @Override
    public int execute() throws InterruptedException {
        if (!getGrandExchange().isOpen()) {
            openGE();
        } else if (boughtItems()) {
            setFinished();
        } else {
            buyItems();
        }
        return 300;
    }
    
    public void openGE() {
        RS2Object geBooth = getObjects().closest("Grand Exchange booth");
        NPC exchangeWorker = getNpcs().closest("Grand Exchange Clerk");
        
        int random = new Random().nextInt(2);
        if (geBooth != null && random == 0) {
            if (geBooth.interact("Exchange")) {
                new ConditionalSleep(2500, 3000) {
                    @Override
                    public boolean condition() {
                        return getGrandExchange().isOpen();
                    }
                }.sleep();
            }
        } else if (exchangeWorker != null) {
            if (exchangeWorker.interact("Exchange")) {
                new ConditionalSleep(2500, 3000) {
                    @Override
                    public boolean condition() {
                        return getGrandExchange().isOpen();
                    }
                }.sleep();
            }
        }
        
    }
}

 

I also recommend using this class for conditional sleeps: 

 

 

 

 

 

Edited by Canidae

There is no way that file doesn't exist. Anyway, it's not possible to tell how you got the null pointer exception with the code you are showing us. Most likely, some part of your code isn't null checking when dealing with widgets. But it could be something else too.

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.