Reputation: 38705
I try to use the following code:
ArrayList<String>
Map<String, String>
Eclipse complains about both of them: Syntax Error, parameterized types are only if source level is 1.5.
I use JDK 1.6, but even if I go to compiler and switch the compliance to 1.5. It still give me this error. Any Idea why?
Upvotes: 44
Views: 129680
Reputation: 612
I get this fairly regularily. Currently what's working for me (with Photon) is:
If this doesn't work :
I know, stupid isn't it.
Upvotes: 0
Reputation: 63
Do the following..
Right-click on your project--> select properties-----> select Java Compilers
You wills see this window
Now check the checkbox ---> enable project specific settings.
Now set the compiler compliance level to 1.6
Apply then Ok
now clean your project and you are good to go
Upvotes: 1
Reputation: 1
THIS CAN BE A QUICK FIX FOR ECLIPSE
When I was trying to create array list it gave error that array list cannot be resolved to type and something about "parametrised type are only in level 1.5"
Only I did was I tried to import java.util.ArrayList;
And that error went away.
Upvotes: 0
Reputation: 57
change the compiler version to lower value and do apply the changes. The compilation will fail.
Now update the version to required and do apply the changes, the workspace will get rebuild and the issue will get resolved.
Upvotes: 0
Reputation: 33636
My guess would be that while you run eclipse itself with JDK 1.6, it's actually configured with a different default jre.
See Window->preferences->java->Installed JREs
and make sure that the checked JRE is 1.6
.
If the default JRE is indeed 1.6, chances are that it's a project specific setting. See that the project is configured to use the right JRE.
Upvotes: 23
Reputation: 932
This works for me .
In eclipse go to project properties -> java compiler.
Then change to java higher than 1.5 .
change Compiler compliance settings to 1.6 change Generated.class files compatibility to 1.6 change Source compatibility to 1.6
Upvotes: 7
Reputation: 839
Single answer couldn't solve my problem so I used both :
.... tada...done... :)
Upvotes: 2
Reputation: 11
It can be resolved as follows:
Go to Project properties.
Then 'Java Compiler' -> Check the box ('Enable project specific settings')
Change the compiler compliance level to '5.0' & click ok
Select the checkbox for "Use default compliance settings"
Upvotes: 1
Reputation: 421
It can be resolved as follows:
Go to Project properties.
Then 'Java Compiler' -> Check the box ('Enable project specific settings')
Change the compiler compliance level to '5.0' & click ok.
Do rebuild. It will be resolved.
Also, click the checkbox for "Use default compliance settings".
Upvotes: 42
Reputation: 169
I'm currently working with Eclipse Luna. And had the same problem. You might want to verify the compiler compliance settings, go to "Project/Properties/Java Compiler"
The Compiler compliance level was set to 1.4, I set mine to 1.5,(and I'm working with the JDK 1.8); it worked for me.
And if you had to change the setting; it might be useful to go to "Window/Preferences/Java/Compiler" And check to see that the Compiler compliance level is 1.5 or higher. Just in case you have a need to do another Java project.
Upvotes: 0
Reputation: 71
Go to Project properties.
Then 'Java Compiler' -> Check the box and "Enable project specific settings"
Uncheck the box to "Use Compliance from execution environment 'OSGi/Minimum-1.2' on the Java"
Then change the compiler compliance level to '1.5' and click Ok.
Rebuild it and your problem will be resolved.
Upvotes: 7
Reputation: 21
I have experienced the same problem with Eclipse Indigo release - even though the project set up was correct. The main cause I suspect is that the workspace is defined in a separate folder from the actual source folders (as mentioned user748337). To fix the problem, I had to enable the project specific settings option (in the Porject preference) although it wasn't different from the workspace settings.
Upvotes: 2
Reputation: 421
This workaround is helpful when this problem pops up.
1) Set Workspace JRE to 1.5 (and apply/save). Projects will rebuild.
2)Set Workspace JRE back to 1.6 (and apply/save). Projects will rebuild.
All errors are then gone (for now at least).
Upvotes: 42
Reputation: 121
Be wary, too, of inheriting workspace settings in your projects for Java Compiler/Compliance settings. I had a project that was imported into Eclipse. Eclipse generated the project with a J2SE 1.4 JRE, compiler, and compliance settings.
When I went in and manually updated these settings and un-checked the "Enable project specific settings" box, I was still receiving build errors relating to 1.5 level compliance (even though the workspace settings were clearly 1.6). It wasn't until I re-checked the "Enable project specific settings" box and manually set the compiler/compliance levels to 1.6 did the errors go away.
Upvotes: 1
Reputation: 11
I was able to solve this in Eclipse Helios by right-clicking on the project, picking "Java Build Path", "Add Library...", "JRE System Library", "Workspace default JRE (jdk1.6.0_17)" and finally "Finish".
Upvotes: 1
Reputation: 211
Yes. Regardless of what anyone else says, Eclipse contains some bug(s) that sometimes causes the workspace setting (e.g. 1.6 compliant) to be ignored. This is even when the per-project settings are disabled, the workspace settings are correct (1.6), the JRE is correctly set, there is only a 1.6 JRE defined, etc., all the things that people generally recommend when questions about this issue are posted to various forums (as they often are).
We hit this irregularly, but often, and typically when there is some unrelated issue with build-time dependencies or other project issues. It seems to fall into the general category of "unable to get Eclipse to recognize reality" issues that I always attribute, rightly or wrongly, to refresh issues with Eclipse' extensive metadata. Eclipse metadata is a blessing and a curse; when all is working well, it makes the tool exceedingly powerful and fast. But when there are problems, the extensive caching makes straightening out the issues more difficult - sometimes much more difficult - than with other tools.
Upvotes: 21
Reputation: 68942
Right click your project and choose properties in the properties dialog check the Java Compiler settings, maybe you have different workspace settings.
Upvotes: 5