Running exit() from settings() causes NullPointerException

Any time I try to call exit() from settings(), it will cause a NullPointerException. It will work fine if I call it from anywhere else. Any idea of why? or how to fix it?


  • OK, now I am curious: why are you calling exit() in settings()? This method is to call some specific functions, not to have any logic in it (AFAIK), and if you call exit() there, your sketch just stops. So I fail to see the use case.

  • I was pulling user input from a JOptionPane.showInputDialog in settings so that I could make the screen the size of inputted integers, and I wanted to be able to exit if the user pressed cancel.

  • edited August 2015 Answer ✓

    Create a boolean variable doExit then in settings() test the value returned from JOptionPane and set a the value of doEvxit accordingly. In setup test doExit and call exit() if true.
    That way you avoid calling exit() in settings

  • Thank you so much. I don't know why I didn't think to do that. I have done that in other programs, but I just hadn't thought of that for some reason. Thanks again.

Sign In or Register to comment.