Solved

array out of bound exception error

Posted on 2006-07-22
4
864 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This video teaches viewers about errors in exception handling.

733 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