Bookmark Topic Watch Topic
  • New Topic

getting NullPointerException

 
sudhakar ananth
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hello Friends

I am getting this error when using this code in JOptionPane

"
String text = JOptionPane.showInputDialog(this, message);
if (text.equals("yes"))
{
JOptionPane.showMessageDialog(this,"TEXT ENTERED IS YES");
}else if (text.equals("no"))
{
JOptionPane.showMessageDialog(this,"TEXT ENTERED IS NO");
}else if(text.equals("")){

JOptionPane.showMessageDialog(this,"U DIDN'T ENTERED ANY TEXT");
}
"

Actually when i am clicking Cancel i am getting this EXCEPTION

can any tell how to solve or is there any return type to catch when click
CANCEL button..
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
Yes, showInputDialog returns null on Cancel. Simply test the returned value :

if( text == null ) {
// Cancel
...
}
 
sudhakar ananth
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Report post to moderator
no i have tried this also but it is not helping me....
i am still getting that error
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Report post to moderator
it has to be the first statement in the if/else chain
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please do not post copies of threads - further comments can go to this one.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!