BP Forums
the snake game don't like me. - 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: the snake game don't like me. (/showthread.php?tid=807)



the snake game don't like me. - Aaron Rogers118 - 08-22-2013

I keep geting this error message:

Exception in thread "Thread-3" java.lang.ArrayIndexOutOfBoundsException: 1

at Snake.snakeCanvas.CheckScore(snakeCanvas.java:173)

at Snake.snakeCanvas.Move(snakeCanvas.java:156)

at Snake.snakeCanvas.run(snakeCanvas.java:288)

at java.lang.Thread.run(Unknown Source)

Can anyone help?


Re: the snake game don't like me. - brandonio21 - 08-22-2013

I'm assuming that means you're having problems with this line:
[code2=java]if (score > Integer.parseInt((highScore.split(":")[1])))[/code2]

If this is so, then the problem is that the highScore variable does not actually contain a colon! So the data past the colon could not be retrieved. This can be fixed by adding a check like
[code2=java]if (highScore.contains(":"))[/code2]

So, you could combine them to prevent errors, like so:
[code2=java]if (highScore.contains(":"))
{
if (score > Integer.parseInt((highScore.split(":")[1])))
{
//do stuff here
}
}[/code2]

I hope that this helped!


Re: the snake game don't like me. - Aaron Rogers118 - 08-22-2013

It works! I also watched your latest video on this subject a second time and found some stuff I missed. I also got 460 points! <!-- sSmile --><img src="{SMILIES_PATH}/icon_e_smile.gif" alt="Smile" title="Smile" /><!-- sSmile -->


Re: the snake game don't like me. - brandonio21 - 08-22-2013

I'm glad you were able to find even more stuff that you missed and that you aren't having too much difficulty with the program! It's fun, ain't it?

460 points? Your grandmother could do better in her sleep. <!-- sWink --><img src="{SMILIES_PATH}/icon_e_wink.gif" alt="Wink" title="Wink" /><!-- sWink -->