• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

getting NullPointerException

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Marshal
Posts: 79978
397
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please don't post the same thing twice. I suggest you go into "edit" and delete this post.
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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");
 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

One more thing please try to use null instead of this



What would that achieve?
 
straws are for suckers. tiny ads are for attractive people.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic