jQuery in Action, 3rd edition
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 OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Array dimension missing" Watch "Array dimension missing" New topic

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?

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

Joined: Jul 08, 2003
Posts: 24193

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]
I agree. Here's the link: http://aspose.com/file-tools
subject: Array dimension missing
It's not a secret anymore!