• Post Reply Bookmark Topic Watch Topic
  • New Topic

What does the number indicates in Array index out of range error?  RSS feed

 
khadar valli
Greenhorn
Posts: 26
Java MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Can you please let me know the difference between the below error messages.

Error: Array index out of range:  3
Error: Array index out of range: 1

What does the number indicates?

Thanks in advance.
 
Dave Tolls
Ranch Foreman
Posts: 3065
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's the index that was passed to the array, the one causing the exception.
 
Aditya Soni
Greenhorn
Posts: 17
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lets take an example of array of Strings containing three elements:


now,if you want to access the array element at index 1 it outputs:


second


but if you want to access the array element at index 3 it raise exception as:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3  //the wrong index that doesn't exists in your array
at___________(___.java:4)
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course, the 4 at the end is a line number.
OP: Did you say it prints Error? That doesn't look like normal Java® behaviour. Have you written some instruction to print that?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!