incah
asked on
String problem
I have a String named in. When I call in.charAt(0) I get StringIndexOutOfBoundsExce ption. Why is this happening when the String is neither null nor ""?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Did you call the next method before assigning the String?
Let's say you have a variable called result as ResultSet,
you have to do result.next() first, then you can assign in to result.getString() if there's any row returned
Let's say you have a variable called result as ResultSet,
you have to do result.next() first, then you can assign in to result.getString() if there's any row returned
So you have something like, in=ResultSet.getString();
ResultSet is not null, 'cos you'd get an Null pointer exception... (but it's still worth a check)
Have you try to get the length() of the string, ie in.length(); and see what's the value.
Chris.
ResultSet is not null, 'cos you'd get an Null pointer exception... (but it's still worth a check)
Have you try to get the length() of the string, ie in.length(); and see what's the value.
Chris.
ASKER
The string is not null and has a length because as my method is written it wouldn't reach to the point where in.charAt() is called. Anyway I printed the length to the standard output and it is 4.
ASKER
Please forget the question. The exception was happening when StringBuffer.setCharAt() was called, and not on String.atChar(). My mistake. Sorry.
Well at least you found it :)
ASKER