views:

621

answers:

6

Hi! I have a strange problem with eclipse galileo. I set java 1.6 as jre. And for this line of the code

List templates = new ArrayList ();

I see such error in eclipse problem list:

The type Collection is not generic; it cannot be parameterized with arguments <? extends E>

But I don't have any problems with building this project with ant. How can I fix it? Looks like it is an eclipse problem, but because of this errors I can't compile/publish my project from IDE. Thanks.

+4  A: 

What List are you importing? (see this thread from 2006)

java.awt.List or java.util.List?

Because, as eclipse aptly comments, java.awt.List is not parameterized ;)


Check also the

  • Java Build path: it must not contain a reference to the J2SE 1.4.2 libraries.
  • Source Compatibility: project properties -> Java Compiler Settings, Source Compatibility 5.0 or 6.0.


Other than that, there was lots of issue back in 2005 when the latest Eclipse 3.1 beta was supporting J2SE5, but this was fixed since then.

Try tyo use the latest JDK6 in your project.

VonC
import java.util.List;
dbf
good catch. One of my favorites (when I don't pay attention) - on the other hand - it builds on ant and doesn't complain about List but about Collection.
Andreas_D
+1  A: 

Sometimes it's an eclipse hiccup and eclipse -clean plus refreshing all projects helps.

Edit

Does it change anything when you replace your code with:

java.util.List templates = new java.util.ArrayList();

or even

java.util.List<Object> templates = new java.util.ArrayList<Object>();

?

Andreas_D
I've already tried it. Also I tried to remove .metadata folder and recreate a workspace.
dbf
A: 

Some ideas:

  • check the JRE library being used in your project (check the package explorer).
  • check the installed JREs in the eclipse settings (same as used by ant).
  • comment out the line just to check if it really is the error cause.
  • retype the whole line from scratch.
  • install a new (clean) version of eclipse, in a new folder (testing).
Carlos Heuberger
A: 

put the entry "JRE System Library..." at the top in project, properties, java build path, order and export

Fabio
A: 

For those, who will get there from Google: the problem was with cryptix library. When I removed it from java build path the project is compiled sucesfully.

dbf
A: 

Thanks to dbf, removing the cryptic library does the trick for me...but then I needed this library for my code. So instead of removing it, just need to move the library code to the last order in the eclipse Java build path -> order and export, and that too resolves the error.

HwaSeong