Results 1 to 5 of 5
- 04-26-2012, 02:04 AM #1
Member
- Join Date
- Apr 2012
- Posts
- 2
- Rep Power
- 0
Exception java.lang.NumberFormatException
I was testing one of my starter programs as an attempt to see if I can get a program working, everything went fine until I pressed in !stop to stop putting in numbers and start calculating. My program is an Averaging program which takes a set of data, increments the value of entries every time someone puts in a number and stores the new number in an ArrayList<Integer>. Here's what I was doing:
I have already had knowledge of translation stacktracing, and it tells me line 20, 26, and 38 are broken.Welcome to the Averaging Program.To verify you made this program, please enter a 4-digit pin: 0000
Password accepted.
I will be asking you to input values
Please insert a number, or to stop, type !stop.10
Please insert a number, or to stop, type !stop.10
Please insert a number, or to stop, type !stop.10
Please insert a number, or to stop, type !stop.!stop
Exception in thread "main" java.lang.NumberFormatException: For input string: "!stop"
at java.lang.NumberFormatException.forInputString(Unk nown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at Averaging.loopInsert(Averaging.java:38)
at Averaging.verify(Averaging.java:26)
at Averaging.main(Averaging.java:20)
My main class is on Pastebin at [Java] java.lang.NumberFormatException 1 (Averaging Program) - Pastebin.com
- 04-26-2012, 02:44 AM #2
Senior Member
- Join Date
- Apr 2012
- Location
- New York State of Confusion, USA
- Posts
- 137
- Blog Entries
- 1
- Rep Power
- 0
Re: Exception java.lang.NumberFormatException
You cannot compare strings using:
Depending on your needs, the String class provides many ways to compare strings. In your case, all you need is:Java Code:if(next == "!stop")
Java Code:if(next.equals("!stop"))
- 04-26-2012, 03:03 AM #3
Senior Member
- Join Date
- Apr 2012
- Location
- New York State of Confusion, USA
- Posts
- 137
- Blog Entries
- 1
- Rep Power
- 0
Re: Exception java.lang.NumberFormatException
I should have added a bit more. What do you think happens when you test incorrectly and it always evaluated to false, sending you down the else path? One way to debug this would be to print out what next is at the point of the parseInt() call. Even than may not have helped you to realize that how you tested the contents of next was incorrect, but it would have helped to zero in on the problem....like why on earth am I ending up in that else when my input was clearly !stop?
- 04-26-2012, 09:26 PM #4
Member
- Join Date
- Apr 2012
- Posts
- 2
- Rep Power
- 0
Re: Exception java.lang.NumberFormatException
Your first post:
Thanks for this.
Your second post:
I wanted to do the input !stop so the user using the program can stop entering numbers into an ArrayList<Integer> and start calculating.
This is only my first piece of software I have created. I'm still trying to learn how to make certain stuff (like IO managing [I know some, and can do YML file making in the program], and such).
- 04-26-2012, 10:12 PM #5
Senior Member
- Join Date
- Apr 2012
- Location
- New York State of Confusion, USA
- Posts
- 137
- Blog Entries
- 1
- Rep Power
- 0
Similar Threads
-
Exception in thread "main" java.lang.NumberFormatException:input string: "060320
By renu in forum New To JavaReplies: 14Last Post: 04-08-2011, 06:01 PM -
Exception in thread "main" java.lang.NumberFormatException: Value out of range. Value
By jav2000x in forum New To JavaReplies: 5Last Post: 04-12-2010, 03:39 PM -
[newbie] Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException:
By jon80 in forum New To JavaReplies: 3Last Post: 06-07-2009, 12:14 AM -
Exception java.lang.NumberFormatException
By vasavi.singh in forum New To JavaReplies: 3Last Post: 02-24-2009, 06:27 AM -
java.lang.NumberFormatException: null
By Eric in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 07-05-2007, 05:31 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks