Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# ArrayIndexOutOfBoundsException

Posted on 2003-11-27
Medium Priority
193 Views
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
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
• 3

LVL 35

Expert Comment

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

should be

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

LVL 35

Expert Comment

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

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

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

you were doing it right..
0

Author Comment

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

Question has a verified solution.

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

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…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
###### Suggested Courses
Course of the Month8 days, 20 hours left to enroll