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 java error 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 "java error" Watch "java error" New topic
Author

java error

Don Williams
Greenhorn

Joined: Jun 02, 2006
Posts: 6
C:\Sun\AppServer\jdk\bin\Student.java:31: array dimension missing
Student pupil[i] = new Student[];
^
1 error

I have tried corrected but it seems that I am not setting up my array correctly.

Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Based on your comment,

// create an array of 10 student objects from class Student...

your array declaration would look like

Student[] students = new Student[10];

Note that you want this outside your for loop, not inside; you want to create the array, then visit each element, right?

Now, this just gives you an array of 10 Student variables; the variables are all null. If you need objects, then you need to create those too; for example, inside your for loop, at the top, you might have

students[i] = new Student();

this would fill each element of the array with a Student object as you visited it.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java error
 
Similar Threads
Java Object Oriented Grades Program
A little help with a null pointer exception
having problem in verifying a character
to Dave Lander,Marilyn de Queiroz
Error in calculation