In Java, subString complains of having a negative index... yet neither the start nor

sunmaz_1234567

New member
Joined
Nov 14, 2010
Messages
1
Reaction score
0
Points
1
end are negative. help!? this.proteinSequence = sDNA.substring(startAt, endAt); <---- The line of code causing the Exception.

proteinSequence is a String.
sDNA is a String of length > 16 000 characters.
In this example, startAt = 3306 and endAt = 3192.
When run I get the following bizarre error:

"Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -114"

Any help would be greatly appreciated!
What other code could you need? My issue is that both the indicies are in bounds....that is why I am confused.
 
How can we tell when you've given us jack squat worth of code? Out of bounds means you used a value that does not exist in the string. You either went over or under the index.
 
Back
Top