[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

array out of bound exception error

Posted on 2006-07-22
4
Medium Priority
?
871 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 500 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

Independent Software Vendors: 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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
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…
Suggested Courses

649 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