Solved

ArrayIndexOutOfBoundsException

Posted on 2003-11-27
4
190 Views
Last Modified: 2010-03-31
Hi Experts!

I have the following code in a program:

 szOperType = new String[nRows];
        for ( i = 0; i <= nRows; i++ )
          szOperType[i] = "";

nRows is an integer and I previously gatter it. szOperType is an array of Strings. I am getting an ArrayIndexOutOfBoundsException when nRows == 0. I do not know why it wont let me create an array of 0...does anyone knows how??

Thank you Experts! I'll give 100 points for it! :)

pupieye
0
Comment
Question by:pupieye
[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 35

Expert Comment

by:TimYates
ID: 9832558
for ( i = 0; i <= nRows; i++ )

should be

 for ( i = 0; i < nRows; i++ )
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9832570
arrays go from index zero, up to (not including) their length

ie:  from zero for [length] number of elements

When you were setting yuor array to length 0, your loop would still try and access element zero

which didn't exist
0
 
LVL 35

Accepted Solution

by:
TimYates earned 100 total points
ID: 9832624
> does anyone knows how??

nRows = 0 ;
szOperType = new String[ nRows ];

you were doing it right..
0
 

Author Comment

by:pupieye
ID: 9833592
I think I know why....When I was trying to create the array

szOperType = new String[ nRows ];

since nRows =0 I was  not creating an array of zero length, so that was my mistake...

Anyway...since you were the only one who answer...those points go to you buddy!

Regards!

Francisco
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 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…
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 the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
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…

734 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