This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes ArrayList problems... Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "ArrayList problems..." Watch "ArrayList problems..." New topic
Author

ArrayList problems...

Eddie Appell
Greenhorn

Joined: Apr 26, 2005
Posts: 3
I'm working my way through the "Head First Java" book and making good progress. I've gotten about 2/3 of the way through and nearly all of the sample code works fine. The only time I've encountered an error in the code is when they try to create a new ArrayList using the new syntax. Here's an example:



When I type this code into Eclipse I get an error on the line above the ArrayList line. The error is: "Syntax error on token ";", = expected." If I remove the type declaration (<JCheckBox> , then the code doesn't execute properly. They've done this in a few places in the sample code and every time I encounter a typed ArrayList I get an error. I do have jdk 1.5.03 installed and selected as the default JRE in Eclipse, and from what I can tell, it should support this syntax...? Any idea what I'm doing wrong?

Thanks for your help!

Eddie
Gregg Bolinger
Ranch Hand

Joined: Jul 11, 2001
Posts: 15230

What version of Eclipse? It may just be that the syntax isn't supported in the IDE version even though the VM supports it. Have you tried compiling outside of Eclipse? That should be an indicator.
Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
My guess is that you'll need to update your version of Eclipse to version 3.1 which was the first version to properly support JDK1.5
Eddie Appell
Greenhorn

Joined: Apr 26, 2005
Posts: 3
I am running Eclipse 3.0.2, so if 3.1 is the first version to support the new syntax, then I'm sure that's part of the problem. But when I try to compile the file at a command line I get errors in those lines as well:



I checked my version and I do get java version "1.5.0". So even if I upgrade Eclipse, it looks like there's still something wrong with the code...?

I'll upgrade Eclipse, and in the mean time if anyone else has any other suggestions please let me know!

Thanks,

eddie
Jack Conway
Ranch Hand

Joined: Aug 10, 2003
Posts: 30
Upgrading to Eclipse 3.1 is definitely the solution.

Compiling from the command line is something I haven't done for a while, but my guess is that you need the following command line switch



As I think the default is to remain in Java 1.4 and earlier mode, for backward compatibility.

Good luck
[ May 25, 2005: Message edited by: Jack Conway ]

Co-author, <a href="http://www.ariadnetraining.co.uk/books.htm" target="_blank" rel="nofollow">Java Programming and Enterprise Java</a> (free download)
Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
if you type in javac -version what do you get?
I get: javac 1.5.0_02
It is possible you have the JRE of 1.5 but the SDK of an earlier version in your Path. What do you get when you type in echo %Path% ?
Eddie Appell
Greenhorn

Joined: Apr 26, 2005
Posts: 3
Ah, that was it - I had the JRE for 1.5 installed, but not the jdk. I've installed it and now it compiles without errors. I'm currently upgrading Eclipse to 3.1 so it will support the new syntax.

Thanks for your help!

eddie
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: ArrayList problems...
 
Similar Threads
Troublesome logic error
Sharing bean properties between forms
ClassCastException pulling list from session
Another HFJ BeatBox question - re: track.remove() method
Collection specific elements not generic problem