Solved

array out of bound exception error

Posted on 2006-07-22
4
862 Views
Last Modified: 2012-08-13

Hello there,

i get this error java.lang.ArrayIndexOutOfBoundsException: 0, when i try to do this.
String cmbList[] =new String[0];
System.out.println("Inside ELSE"+cmbList[0]);

what is the problem.

cheers
zolf
0
Comment
Question by:zolf
  • 3
4 Comments
 
LVL 5

Accepted Solution

by:
maclema earned 125 total points
ID: 17162352
String cmbList[] =new String[1];

when creating the array it is 1 based, so what you are doing is creating an empty array with no elements
0
 

Author Comment

by:zolf
ID: 17162372

could you please explain in more detail why i was getting the error.please.array start with 0, am i right
0
 
LVL 5

Expert Comment

by:maclema
ID: 17162520
ArrayIndexOutOfBounds means that you are trying to access an array elements that does not exist:

Picturs this.

String arr[] = new String[3];

this would look something like this

["", "", ""]

So when you do

String srr[] = new String[0];

you get this:

[]  << see no elements


When access array elements it is 0 based, 0 is the first element in the array, but if you have no elements in the array, there is nothing to access!
0
 
LVL 5

Expert Comment

by:maclema
ID: 17162523
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Weekend adv creator 3 51
jdbc error in jsp application 20 63
by zero exception 10 52
Convert from a json string array to a Java object 3 51
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question