This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes String index out of range exception Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "String index out of range exception" Watch "String index out of range exception" New topic
Author

String index out of range exception

Avi Sridhar
Ranch Hand

Joined: May 31, 2007
Posts: 42
Hello All, thanks for your helpful tips.

I once again stumbled upon this index out of range exception.



the exception i am getting is

[BOLD]

Exception in thread "main" java.land.StringIndexOutOfBoundsException: String index out of range: -6

[/BOLD]

any pointers will be greatly appreciated.

Thanks
Avi Sridhar
Ranch Hand

Joined: May 31, 2007
Posts: 42
Originally posted by Avi Sridhar:
Hello All, thanks for your helpful tips.

I once again stumbled upon this index out of range exception.



the exception i am getting is

[BOLD]

Exception in thread "main" java.land.StringIndexOutOfBoundsException: String index out of range: -6

[/BOLD]

any pointers will be greatly appreciated.

Thanks


Please note the longKey has a length of 60 too
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32833
    
    4
Originally posted by Avi Sridhar:


Please note the longKey has a length of 60 too
No, it hasn't. If you write "long string" it has a length of 11; your comment about length = 60 is mistaken.
You will need to check the lengths of your keys carefully; they are probably not 60. If you are actually getting -6 then (q + s1 + s2 + s3) must be a negative amount.
Avi Sridhar
Ranch Hand

Joined: May 31, 2007
Posts: 42
Originally posted by Campbell Ritchie:
No, it hasn't. If you write "long string" it has a length of 11; your comment about length = 60 is mistaken.
You will need to check the lengths of your keys carefully; they are probably not 60. If you are actually getting -6 then (q + s1 + s2 + s3) must be a negative amount.


thanks for the reply. I ment to say that "a long string" , as an example.... and that string has a length of 60. The Short and long strings both of lengths of 60 too...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32833
    
    4
In which case you might be calling substring(3, 1). You can't have the first number larger than the second number. Read this.
Avi Sridhar
Ranch Hand

Joined: May 31, 2007
Posts: 42
Originally posted by Campbell Ritchie:
In which case you might be calling substring(3, 1). You can't have the first number larger than the second number. Read this.


Thanks for the information. I just happened to fix that.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: String index out of range exception
 
Similar Threads
Uploading jpeg images to webserver
JList problem
substring(int i)
Problem with JList
Problem with Email Program in TCP