Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JOptionPane errors with 0 length input  RSS feed

 
Don Smathers
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using JOptionPane.showInputDialog(" asdfsfasdf " );
I get a system error when I simply press the OK button without
entering any data.
Can you please suggest a way to avoid this while still staying
within the confines of JOP?
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is really a Swing question, so I've moved it to the Swing/AWT forum for you.
 
Stephanie Grasson
Ranch Hand
Posts: 347
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Don.
I have tried using
String text = JOptionPane.showInputDialog(" asdfsfasdf " );
and have no problem pressing the OK button without entering any data. I am using JDK1.2.2 on an NT4.0 system.
Perhaps you are trying to do something with text (which is an empty String if you click OK without entering any data) and this is causing the error? Can you post that part of your code?
Stephanie
 
Don Smathers
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephanie, you are absolutely correct !!
I adjusted code as follows:
aNbr = JOptionPane.showInputDialog( "What is acct nbr " );
if (aNbr.length() == 0) System.exit(0);
acctNbr = Integer.parseInt( aNbr );//this was failing
and it works just fine --- Many thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!