Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ArrayIndexOutOfBounds Exception

 
Ravi Kotha
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have a problem in accesing array elements. Please look at the code.


Based on the algorithm I have choosen, the calculated value of "d" should fall with in the range of array size. The same code was working when I use it in Java script.
Code I used in Jscript:


My question is when I used in Jscript I do not get any array index out of bound exception, but in case of Java I do get the exception. Whats wrong with the code? Can somebody share your thoughts? Thanks

[ inserted line breaks for readability - Jim ]
[ December 22, 2006: Message edited by: Jim Yingst ]
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This looks strange to me:You calculate this value d, which from your comments is intended to be an array index, but then you ignore it and use some other value.
 
Ravi Kotha
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey iam sorry, it was not 'r' its 'd' only. I misplaced 'd' with 'r'.
Here is corrected one.

 
Henry Wong
author
Marshal
Pie
Posts: 21128
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The stack trace for the ArrayIndexOutOfBoundsException will tell you which index it is trying to access. With that information, you can tell which element is being accessed.

Henry
 
Ravi Kotha
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya, i know that. My question is is there any difference in saying


AND


In the first case 'c' value is within the range of array, where as its not in second case.
 
Henry Wong
author
Marshal
Pie
Posts: 21128
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the first case 'c' value is within the range of array, where as its not in second case.


You are assuming that it is the index that is wrong... To confirm that you need to print out the indexes for both operations -- working and not working to see if they are the same.

Another option is that the array could be wrong. Is the other array also a string array? or is it a byte array?

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic