java - JOptionPane showInputDialog cancel button NullPointerException -


i trying unsuccessfully trap user entering filename. i'm using input dialog because path , extension predetermined, , need append filename after user enters it. title says nullpointerexception time user clicks cancel button. since input dialog has no way remove cancel button i've resorted method:

while (filename.equals(null) || filename.equals("")) {     filename=joptionpane.showinputdialog(this, "please enter filename.");     if (filename.equals(null)) filename=""; } 

i wouldn't have filename.equals(null) in 2 places that, tried both separately , out of frustration tried too. nullpointerexception still occurs on line:

if (filename.equals(null)) filename=""; 

is there way trap cancel button (null) or prevent it?

  filename.equals(null) // compare object  

should like

  filename == null // compare object references 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -