Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ArrayList problems...

 
Eddie Appell
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 703
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Nigel Browne
Ranch Hand
Posts: 703
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic