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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getting NullPointerException

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
no i have tried this also but it is not helping me....
i am still getting that error
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
it has to be the first statement in the if/else chain
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Please do not post copies of threads - further comments can go to this one.
 
    Bookmark Topic Watch Topic
  • New Topic