简体   繁体   中英

eclipse magic: … Syntax error, varargs are only available if source level is 1.5 or greater

Yesterday I made a project in eclipse, and it was working, compiling. I used Eclipse Galileo for Java EE. Today I open eclipse and see lots of errors saying that stuff is not available and that it is only available if source level is 1.5.

What to do?

Check whether this works:

  1. Go to your project's Properties
  2. On the Properties dialog choose the Java Compiler node in the left tree.
  3. Finally set the Compiler compliance level to 1.5 or more.
  4. Rebuild the project.

Single answer couldn't solve my problem so I used both :

  • First right click on the error in problems tab
  • click Quick fix
  • ok
  • right click on the project
  • build path
  • configure build path
  • remove JRE library
  • add JRE library

.... tada...done... :)

Just make sure Java > Installed JREs has jre6 instead of jdk1.6.0

Eclipse seems detect jdk6 as not jre 1.5+

If your JDK is already at or above 1.5 try changing your JDK compliance to something else, letting it build, and then back again.

  1. Open Preferences (Window -> Preferences)
  2. Navigate to Java -> Compiler
  3. Change the Compiler compliance level to some other value
  4. Hit Apply and allow eclipse to rebuild
  5. Repeat steps 3 & 4 with desired Compiler compliance level

See also: Eclipse: Syntax Error, parameterized types are only if source level is 1.5

(I know, I know, this question is older by a year, but the other one contains some additional info in Jeff's answer.)

  1. Open Window | Preferences.
  2. Java | Compiler.
  3. Change compiler compliance level to some other value.
  4. Hit apply, allowing eclipse to build.
  5. Change compiler compliance level to desired level of Java.

Try this:

Go to your project's Properties, set the Java Compiler compliance level to 1.6, let it rebuild the project, then switched back to 1.7 and rebuild it again.

It worked for me :)

Perhaps your project lacks in some necessary jars. Try this:

  • Right click your project>>build path>>select libraries>>add jars to add necessary jars in your project.
  • Go to your project's Properties, set the Java Compiler compliance level to 1.6 or above.
  • Go to your project's Properties,set the project facets. make the 'java' option to match your Java Compiler compliance level,such as '1.6'.

I had the same issue. For me, my project's compiler settings were imported from my Workspace Configuration settings, which was set to 1.8...

I tried switching compiler levels and rebuilding, but no luck. What did the trick though, was the following:

On your file system

  1. Navigate to your project.

  2. Delete the .settings folder.

  3. Delete the .project file

In Eclipse:

  1. Delete the project from your workspace - Ensure that you do not check the "Delete project contents on disk..." checkbox

  2. Import your project and allow it to build

I had the same issue after I installed Eclipse on Centos 7.

However in my case changing the Compiler compliance level did not fix the problem.

To fix the problem I changed the Eclipse Installed JREs Window->Preferences->Java->Installed JREs path , which was /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64 to an Oracle JDK at /usr/lib/jdk1.8.0_121-linux-x64

After this change the problem went away.

and something interesting for GWT. even though i am using java 6, it throw me error saying source level should be 5 or later.

Click the error, use the auto correct of eclipse, it change the compliance level to 5, solved the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM