• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String index out of range exception

 
Avi Sridhar
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50171
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50171
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic