Skip 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.

Issue with GUI & NPE

Featured Replies

Hi,

I'm currently working on a fighting script with a gui, and when I try to start the script im getting a NPE before I even select my options on my gui.

Does anyone know why this is happening? I'm getting the NPE on the 1st if() statement if(gui.getMonster().equalsIgnoreCase("chicken")) because getMonster hasnt been answered yet.

public void onStart() throws InterruptedException {
    gui = new fighterGUI();
    if(gui.getMonster().equalsIgnoreCase("chicken")){
        targetMonsterName = gui.getMonster();
        log(targetMonsterName);
        //targetMonsterArea = new Area(pos1, pos2);
    }
    if(gui.getMonster().equalsIgnoreCase("chaos druid")){
        targetMonsterName = "Chaos druid";
        log(targetMonsterName);
        //targetMonsterArea = new Area(pos1, pos2);
    }
    if(gui.getFood().equalsIgnoreCase("salmon")){
        selectedFood = "Salmon";
        log(selectedFood);
    }
    if(gui.getFood().equalsIgnoreCase("lobster")){
        selectedFood = gui.getFood();
        log(selectedFood);
    }

 

class fighterGUI extends JDialog implements ActionListener {
    private final JLabel monsterLabel;
    private final JLabel foodLabel;
    private final JComboBox monsterDropDown;
    private final JComboBox foodDropDown;
    private final JButton button;
    private int monsterIndex;
    private int foodIndex;
    private String monsterName;
    private String foodName;
    private String[] monsterList;
    private String[] foodList;
    private boolean started;

    public fighterGUI() {
        monsterList = new String[]{"Chicken", "Chaos druid"}; //{"Chicken", "Cow", "Goblin", "Hill giant", "Chaos druid"};
        foodList = new String[]{"Salmon", "Lobster"};
        setTitle("Vain's Low Level Combat Fighter");
        setResizable(false);
        setLocationRelativeTo(null);
        setVisible(true);
        setSize(600, 100);
        setModal(true);
        setLayout(new FlowLayout());
        monsterLabel = new JLabel("Select Monster");
        monsterDropDown = new JComboBox(monsterList);
        foodLabel = new JLabel("Select Food");
        foodDropDown = new JComboBox(foodList);
        button = new JButton("Start Script");
        //button.addActionListener(this);
        button.addActionListener(e -> {
                    started = true;
                    close();
        });
        add(monsterLabel);
        add(monsterDropDown);
        add(foodLabel);
        add(foodDropDown);
        add(button);
        pack();
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        //monsterIndex = monsterDropDown.getSelectedIndex();
        setMonster((String) monsterDropDown.getSelectedItem());
        //foodIndex = foodDropDown.getSelectedIndex();
        setFood((String) foodDropDown.getSelectedItem());
        //dispose();
    }

    public void setMonster(String monster) {
        this.monsterName = monster;
    }
    public String getMonster(){
        return monsterName;
    }
    public void setFood(String food){
        this.foodName = food;
    }
    public String getFood(){
        return foodName;
    }
    public boolean isStarted() {
        return started;
    }
    public void open() {
        setVisible(true);
    }
    public void close() {
        setVisible(false);
        dispose();
    }

Could do 

public void onStart() throws InterruptedException {
    gui = new fighterGUI();
    while (gui.isVisible()) {
		sleep(1000);
	}
	.
	.
	.
}

to make it wait

  • Author

@camaro 09 Thanks. I ended up adding an open() method that sets the GUI as visible. Since it's a dialog it requires an answer, so I open() the GUI and it doesn't run through anything else until the GUI has been closed. Fixing the problem :)

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

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.