0

I am using try/catch for an incorrect input for a dialog box that only accepts integers. I was told by my TA that I need to import something. I tried this but still get the same error on line 8:

import java.lang.NullPointerException; //put this where it should be


try
{
    buttons.rotatebutton(); //method I created
}
catch (NumberFormatException | NullPointerException e)
{
    System.out.println("Please type a number");
    if (e == NullPointerException) //ERROR OCCURS HERE
    {
        System.out.println("User cancelled");
    }
}

Can anyone shed some light?

darylnak
  • 239
  • 4
  • 14
  • 2
    Possible duplicate of [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) – laminatefish Nov 12 '15 at 10:46

1 Answers1

1

If you want to check if your object e is a NullPointerException, you have to use the operator instanceof instead of == :

if (e instanceof NullPointerException) {
    System.out.println("User cancelled");
}
Patrick
  • 831
  • 11
  • 25