Solved

array out of bound exception error

Posted on 2006-07-22
4
860 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
xampp tool 12 51
javap not working 8 46
tomcat startup error 5 66
How to convert from xls to xlsx using java 7 41
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
The viewer will learn how to implement Singleton Design Pattern in Java.

822 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