Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to getInt

 
wong chang kit
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



 
wong chang kit
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys.

After I added in my code.

I got an error. Saying that
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "2,000"


Anyone knows how to solve it?
 
Randall Twede
Ranch Hand
Posts: 4371
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"2,000" can't be changed to a number. "2000" can
 
wong chang kit
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But the thing is that I'm using



The format is fixed. Whatever numbers that I typed in. It will automatically change to 2,000 with the comma .
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wong chang kit wrote:in my code.

I got an error. Saying that
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "2,000"

In the code you didn't post?

To get better help sooner, post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that demonstrates the problem.

Before that, read the API for JFormattedTextField and make sure you're using the correct method to obtain the value.
 
wong chang kit
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Anyone knows how to remove the comma between "2,000"
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "2,000"


by the way, I'm using JTextField Value = new JFormattedTextField(NumberFormat.getInstance());
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You obviously haven't followed Darryl's advice to read the Javadoc, because there is a method to get the value of the field.
 
wong chang kit
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did..but I could not get what I'm looking in the website.
 
Rob Spoor
Sheriff
Pie
Posts: 20511
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll say it again: can you find a method with which you can get the Value?
Note that that method does not need to return an int; JFormattedTextField is a bit more generic (not with <T> though) than just for numbers, it can also be used for anything that can be formatted (like dates). You will have to check what the actual class of the object is, and then retrieve an int from that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic