jQuery in Action, 2nd edition*
The moose likes Swing / AWT / SWT and the fly likes For input string: “” when textfields are filled out Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "For input string: “” when textfields are filled out" Watch "For input string: “” when textfields are filled out" New topic
Author

For input string: “” when textfields are filled out

Camilla Kaasi
Greenhorn

Joined: May 09, 2013
Posts: 1

I am writing a program in Java where I got some textfields and a button.

I get a java.lang.NumberFormatException: For input string: "" even though I have filled out all the textfields when running the program.

This is my code:

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Can you tell us which line of code throws that exception? You'll find that information in the stack trace.

It looks like you think that line 101 of your posted code is the problem, but you catch the NumberFormatException which it might throw and print a useless message to the console. So it can't be that line. So it must be some other line. Unless perhaps you are running code which isn't the same as the code you posted.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2153
    
    7
The problem is that you are trying to manage the swapping of panels in your content pane and you are doing it incorrectly. This results in the something() method being called twice which creates two copies of your tabbed pane. One tabbed pane is added to the frame. The other just exists in memory. So the reference to the text field only exists in memory and can never be updated by the GUI and is therefore always empty.

This can be demonstrated by the following change:



Note, this is not the proper solution. You should NOT be trying to manage the swapping yourself. I am sure this is not the only problem with your code.

The proper solution is to use a Card Layout. Let the CardLayout do the swapping of the panels for you.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

And, welcome to the Ranch!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: For input string: “” when textfields are filled out
 
Similar Threads
JTabbedPane with Keyevents
Why aren't my components wrapping?
Help with combobox and pop window
AWT-EventQueue-0" - need Help
Help on Tooltip