File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes String index out of range exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
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: 37985
    
  22
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: 37985
    
  22
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: String index out of range exception
 
Similar Threads
substring(int i)
Problem with JList
Problem with Email Program in TCP
JList problem
Uploading jpeg images to webserver