wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes getting  NullPointerException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "getting  NullPointerException" Watch "getting  NullPointerException" New topic
Author

getting NullPointerException

sudhakar ananth
Ranch Hand

Joined: Feb 02, 2007
Posts: 68
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

Joined: Oct 13, 2005
Posts: 37923
    
  22
Please don't post the same thing twice. I suggest you go into "edit" and delete this post.
Md.Afzalur Rashid
Ranch Hand

Joined: Oct 29, 2002
Posts: 47
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


Be Confident,be trusty,Count your age by friends not by years
Md.Afzalur Rashid
Ranch Hand

Joined: Oct 29, 2002
Posts: 47
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

Joined: Jul 27, 2006
Posts: 131
One more thing please try to use null instead of this


What would that achieve?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getting NullPointerException
 
Similar Threads
CONVERSION ERROR
How to handle cancel option in JOptionPane
getting NullPointerException
handling cancel action effectively
problem with exception