-3

When I add this code:

    otionHover = false;
    if(optionRect.contains(Mouse.getX(), Mouse.getY())) {
        otionHover = true;
        if(Mouse.isButtonDown(0)) {
            System.out.println("The button was pressed!");
        }
    }

I get the error:

Exception in thread "main" java.lang.NullPointerException at lt.CobaltPlanet.nelixus.state.GameMenu.init(GameMenu.java:26) at lt.CobaltPlanet.nelixus.Main.initStatesList(Main.java:55) at org.newdawn.slick.state.StateBasedGame.init(StateBasedGame.java:164) at org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:393) at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:317) at lt.CobaltPlanet.nelixus.Main.main(Main.java:74)

SteveFerg
  • 3,466
  • 7
  • 19
  • 31
Nelixus
  • 31
  • 9

1 Answers1

0

optionRect is null. Make sure to assign something to it, probably a Rectangle.

optionRect = new Rectangle(x, y, width, height);

Is what you need. Just add proper values and it should work.

JackWhiteIII
  • 1,388
  • 2
  • 11
  • 25