• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ArrayIndexOutOfBounds Exception

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey iam sorry, it was not 'r' its 'd' only. I misplaced 'd' with 'r'.
Here is corrected one.

 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic