• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

For input string: “” when textfields are filled out

 
Camilla Kaasi
Greenhorn
Posts: 1
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21111
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2599
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21111
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And, welcome to the Ranch!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic