| Author |
Getting an error from a charAt command
|
Alex Ba
Ranch Hand
Joined: Oct 14, 2009
Posts: 35
|
|
I'm getting a Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 0
at
And I'm not entirely sure why. Place is initialized and set to 0.
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
|
The error message says there isn't a character at position 0 (which would be the first character) of the string. Based on that you can draw a conclusion about the number of characters in the string.
|
 |
Alex Ba
Ranch Hand
Joined: Oct 14, 2009
Posts: 35
|
|
|
But it prints "Please Vote" and then doesn't give an opportunity to fill q...
|
 |
Alex Ba
Ranch Hand
Joined: Oct 14, 2009
Posts: 35
|
|
|
??
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16692
|
|
Alex Ba wrote:But it prints "Please Vote" and then doesn't give an opportunity to fill q...
If I have to take a guess -- since, you didn't show enough code... I am guessing that kb is a reference to a scanner object. And in other places in the code, you used nextInt(), nextFloat(), or simply next(), which leaves the pointer just after the token. So, when you used readLine(), it read from the last token to the end of the line -- which is simply a blank string, since there is nothing between the end of the last token and the carriage return.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
 |
|
|
subject: Getting an error from a charAt command
|
|
|