Jump to content

Error in script onStart()


Renegeade

Recommended Posts

Hello,

 

I'm working on a script for OSBot, but I've run into a bit of an issue that's driving me crazy

 

I try to open up a JFrame in my onStart(), and I always get the error "Error in script onStart()". That would be fine and dandy if I got some kind of exception in the console, but I'm not, so I have no idea why the error is occurring. By printing out things via the logger, I've determined that the issue is occurring in a constructor of mine. However this constructor still causes an issue even if it's blank. 

public void onStart() {
        this.getBot().getLogger().debug("Opening up JFrame...");
        config = new StartConfig(this);
        window = new JFrame("Start PestControlSucks");
        window.setSize(570, 330);
        window.add(config.getControlPane());
        window.pack();
        window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        window.setLocation(dim.width / 2 - window.getWidth() / 2, dim.height / 2 - window.getHeight() / 2);
        window.setVisible(true);
        this.getBot().getLogger().debug("JFrame opened, waiting on user input!");
    }

Based on previous debug messages I left, it never gets past new StartConfig

public StartConfig(PestControl instance) {
        this.instance = instance;
        try {
            instance.getBot().getLogger().debug("Setting up radio group");
            radioGroup.add(radioPurchaseXP);
            radioGroup.add(radioPurchaseVoid);
            radioGroup.add(radioLogOut);
            defaultColor = panelAttack.getBackground();

            instance.getBot().getLogger().debug("Starting to load icons");

            // Experience rewards
            labelAttack.setIcon(loadImageIcon("attack"));
            labelStrength.setIcon(loadImageIcon("strength"));
            labelDefence.setIcon(loadImageIcon("defence"));
            labelRange.setIcon(loadImageIcon("range"));
            labelMagic.setIcon(loadImageIcon("magic"));
            labelHitpoints.setIcon(loadImageIcon("hitpoints"));
            labelPrayer.setIcon(loadImageIcon("prayer"));

            // Void rewards
            labelVoidMace.setIcon(loadImageIcon("void_mace"));
            labelVoidBottom.setIcon(loadImageIcon("void_bottom"));
            labelVoidTop.setIcon(loadImageIcon("void_top"));
            labelVoidMelee.setIcon(loadImageIcon("void_melee"));
            labelVoidRange.setIcon(loadImageIcon("void_range"));
            labelVoidMage.setIcon(loadImageIcon("void_mage"));
            labelVoidGloves.setIcon(loadImageIcon("void_gloves"));

            buttonStart.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    StartConfig.this.instance.reallyStart();
                }
            });
        } catch (Exception ex) {
            instance.getBot().getLogger().debug("Error: " + ex.toString());
            instance.getBot().getLogger().error(this, ex);
            ex.printStackTrace();
        }
    }

However, it never even gets to "Setting up radio group"

 

What's going on? Is there any way to enable stacktraces for onStart()

 

Thanks!

Link to comment
Share on other sites

is startconfig in your main class?  if so why are you passing an instance of PestControl(which i assume is your main class)

 

No, PestControl is the main class. I designed the GUI with Intellij's Swing designer. StartConfig contains the control JPanel, which I add into a JFrame

you can remove everything from on start. Closely add in each line and see which line give you the error.

 

I have already pinpointed the constructor for StartConfig as the error, the rest of onStart works properly

Link to comment
Share on other sites

I ended up using a hacky solution to get the stacktrace from the bot thread. It looks like the NPE was getting thrown in a function called $$$setupUI$$$(), which is automatically generated by Intellij for the Swing designer.

 

I had no clue as to why it wasn't working, so I ended up deleting the form and recreating it, and it worked.

  • Like 1
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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