aspose file tools*
The moose likes Beginning Java and the fly likes not a statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "not a statement" Watch "not a statement" New topic
Author

not a statement

mike hengst
Ranch Hand

Joined: Oct 19, 2002
Posts: 43
Why is this statement not a good one.

the errors are
A:\Projects\SRC\JAVA192\Project3\GradePoint.java:60: not a statement
Student[i] aStudent = new Student();
^
A:\Projects\SRC\JAVA192\Project3\GradePoint.java:60: ';' expected
Student[i] aStudent = new Student();


Thank you Oh Lord<br />For the white blind light<br />A city rises from the sea<br />I had a splitting headache<br />from which the future's made<br />--morrisson
Dave Landers
Ranch Hand

Joined: Jul 24, 2002
Posts: 401
The compiler is expecting something like:
Type identifier = expression;
and of course the result type of the expression has to be compatible with the Type.
You have:
Student[ i ] aStudent = new Student();
..(Type)....(Ident)..=....(Expr)...
Student[ i ] is not a valid type.
It might be a good way to reference the i'th element of an array named Student, but that doesn't work as a Type.
Now, Student[] without the i could be a valid type, as in "an array of Student objects", but that would not match the result of the expression "new Student()" which is of type Student.
I imagine what you want is to assign a new Student() to each element in array of Students.
So you should declare a new array of the desired size, as in:
Student[] theStudents = new Student[ SIZE ];
and then loop thru them and assign a new Student() to each of these, as in:
theStudents[ i ] = new Student();
OK?
[ October 24, 2002: Message edited by: Dave Landers ]
mike hengst
Ranch Hand

Joined: Oct 19, 2002
Posts: 43
That was a good explanation, bout the best I've read of that idea. Here is my code so that you can see what I am trying to do. instantiateStudent is supposed to fill the Student array I have created at the top of the GradePoint class. I think there are a few other errors as well(maybe you could, or someone hel there). Anyways thanks for any time you spend on this. It is something that is due tomorrow night. Also I don't think that I want direct code but rather an explanation of what I have to do.
Dave Landers
Ranch Hand

Joined: Jul 24, 2002
Posts: 401
Just a few comments, based on my "visual compiler" ... javav?


Think about what's happening here - do you really want to call each of these methods twice? I'm not exactly sure what you need to be doing (or so I'm going to claim ) so you need to figure it out.


Since you declared that this method returns a double, you had better make sure that happens, with a "return someDoubleValue;" statement. If you don't want to return something, then don't say that's what yer gonna do.

The compiler does not look at how you use the code, but it does see that it is possible to call this method without having initialized the students array. Might think about rearranging things because of this. Sometimes, if you know better than the compiler, you can get around this message (like initialize the darn thing to some bogus value just to quiet the compiler). But these warnings are worth paying attention to because they usually mean something's amiss in the design/organization of the code.

Ah here's that problem again, but a bit different. One more try and I bet you get it.
What's the name of the array you are assigning to? Is it "Student" or is that the name of the class? Hmmm...
mike hengst
Ranch Hand

Joined: Oct 19, 2002
Posts: 43
Thanks for the help. I think I am very close. I better be I have to be done with by midnight.
I will post my code for you to digest when I have it complete. Everything compiles now but am having a slight array out of bounds issue. Again thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: not a statement