Jump to content

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


Z3Die

Recommended Posts

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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