It's not a secret anymore!*
The moose likes Beginning Java and the fly likes Array dimension missing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Array dimension missing" Watch "Array dimension missing" New topic
Author

Array dimension missing

Stephanie Dears
Ranch Hand

Joined: May 26, 2005
Posts: 43
I have a line in my code:

int array = new int[] array;

the error is array dimention missing

What does this mean?

Steph
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

To declare an array you need something along the lines of

int[] anIntArray = new int[10];

This declares 'anIntArray' to be an array of length 10.


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Stephanie Dears
Ranch Hand

Joined: May 26, 2005
Posts: 43
It's reading from a .txt file.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

You can declare an array of unknown size like this:

int[] array;

but there's no array object there. You can't use "new" to actually create the object until you actually know the size.

If you don't know the size -- that's what we're talking about here, right? -- then don't use an array: use one of the Collections classes in java.util. For example, java.util.ArrayList, which is rather like an array, but it grows automatically as you add items to it.


[Jess in Action][AskingGoodQuestions]
 
 
subject: Array dimension missing