NumberFormatException with Snake - Printable Version +- BP Forums (https://bpforums.info) +-- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=55) +--- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=56) +---- Forum: Java (https://bpforums.info/forumdisplay.php?fid=19) +----- Forum: Programming Help (https://bpforums.info/forumdisplay.php?fid=30) +----- Thread: NumberFormatException with Snake (/showthread.php?tid=812) |
NumberFormatException with Snake - Timkat1994 - 09-16-2013 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 --> Re: NumberFormatException with Snake - brandonio21 - 09-17-2013 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? |