This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes initializing an array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "initializing an array" Watch "initializing an array" New topic
Author

initializing an array

Bron Czimes
Ranch Hand

Joined: May 09, 2004
Posts: 44
ok, i'm trying to put some items into an array based on the outcome of an if statement. I keep getting an error that says i haven't initialized my array properly or something. I'm not sure how to initialize an array if you don't want to put values in straight away, but a bit later on.
Anyway, the code is



Can anyone help?
Bron

Carl - Edited Code to fit on screen
[ June 04, 2004: Message edited by: Carl Trusiak ]
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
What is the Exact Exception message you are getting? Is it an exception during run time or compile? I don't see anything that should be a compile error but, You WILL get an ArrayIndexOutOfBoundsException on the two code lines:

Arrays are Zero based!!! so, the indexes are from 0 - 19

This should be:


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Bron Czimes
Ranch Hand

Joined: May 09, 2004
Posts: 44
aha!
Thankyou.
I do know that arrays are zero-based, but I had changed it for anther part of my program and had forgotten to put it back.
Thankyou for picking up on my absent mindedness

Bron
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: initializing an array
 
Similar Threads
priority queue based on unsorted list(Java's LinkedList Class)
collection class
clarification for jsp code
question about ArrayList
Help with Arrays