Salomao Peixe Salomao Peixe - 4 months ago 17
Java Question

Unexpected string index out of range exception

When running the following code:

if (loja.length() > 0) {
pstmt2.setString(3, loja.substring(0,68));
} else {
pstmt2.setString(3, "_");
}


I got this error:

java.lang.StringIndexOutOfBoundsException: String index out of range: 68

Answer

loja is shorter than 68 chars: StringOutOfBoundsException is being thrown.