• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting NullPointerException

 
sudhakar ananth
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • 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..
 
Campbell Ritchie
Sheriff
Pie
Posts: 50277
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don't post the same thing twice. I suggest you go into "edit" and delete this post.
 
Md.Afzalur Rashid
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try to check for null and then check actual condition using and
if (text!=null&&text.equals("yes"))
{
JOptionPane.showMessageDialog(this,"TEXT ENTERED IS YES");
}else if (text!=null&&text.equals("no"))
{
JOptionPane.showMessageDialog(this,"TEXT ENTERED IS NO");
}else if(text!=null&&text.equals("")){

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



I hope it works....enjoy working
Do not hesitate to opt for any help to me.

Afzalur Rashid
afzal_01@yahoo.com
 
Md.Afzalur Rashid
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more thing please try to use null instead of this in the code like

JOptionPane.showMessageDialog(this,"TEXT ENTERED IS YES");

JOptionPane.showMessageDialog(null,"TEXT ENTERED IS YES");
 
Ricky Clarkson
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more thing please try to use null instead of this


What would that achieve?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic