Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
NumberFormatException with Snake
#1
Hi! I'm following the 8th video of the Snake tutorial and I seem to have missed something and/or completely screwed up. I just started trying to learn Java today and after watching the Tutorials I got started on following the Snake videos. I learn well by example, so these have all been fantastic. I've been at it for hours now, and I can't seem to find what I've done wrong here. The file on the snake page here doesn't have the High Score part added, otherwise I would compare that and mine. Any help would be much appreciated!

Here is the error message:

Exception in thread "Thread-3" java.lang.NumberFormatException: For input string: " 40"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at snakeCanvas.CheckScore(snakeCanvas.java:175)
at snakeCanvas.Move(snakeCanvas.java:142)
at snakeCanvas.run(snakeCanvas.java:267)
at java.lang.Thread.run(Unknown Source)


Here is my progress:
<!-- m --><a class="postlink" href="http://pastebin.com/w7zjJ1fe">http://pastebin.com/w7zjJ1fe</a><!-- m -->
#2
The reason for this seems to be that you are trying to convert " 40" into an integer, which cannot be done because there is a SPACE character within your integer.

Looking at your code, I can't find where that SPACE character is added, though... Hmmm..

Maybe now that you know the problem, you can figure it out?
My Blog | My Setup | My Videos | Have a wonderful day.


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to export Snake Game as a Runnable JAR file? bedigursimran 0 6,810 11-19-2013, 10:01 PM
Last Post: bedigursimran
  the snake game don't like me. Aaron Rogers118 3 14,031 08-22-2013, 10:10 PM
Last Post: brandonio21

Forum Jump:


Users browsing this thread: 1 Guest(s)