简体   繁体   中英

Google App Engine example - error (Java version problem?)

I have followed the instructions for installing the Google App Engine SDK Eclipse plugin:

http://code.google.com/appengine/docs/java/gettingstarted/installing.html http://code.google.com/appengine/downloads.html#Download_the_Google_Plugin_for_Eclipse

I then followed the instructions to create a new project:

http://code.google.com/appengine/docs/java/tools/eclipse.html#Creating_a_Project

However when I try and debug or runt he project within Eclipse I receive the following error:

Exception in thread "main" java.lang.NoSuchMethodError: java.util.Collections.newSetFromMap(Ljava/util/Map;)Ljava/util/Set;
    at com.google.appengine.tools.development.LocalEnvironment.<init>(LocalEnvironment.java:63)
    at com.google.appengine.tools.development.AbstractContainerService$LocalInitializationEnvironment.<init>(AbstractContainerService.java:538)
    at com.google.appengine.tools.development.AbstractContainerService.loadAppEngineWebXml(AbstractContainerService.java:288)
    at com.google.appengine.tools.development.AbstractContainerService.startup(AbstractContainerService.java:160)
    at com.google.appengine.tools.development.DevAppServerImpl.start(DevAppServerImpl.java:172)
    at com.google.appengine.tools.development.DevAppServerMain$StartAction.apply(DevAppServerMain.java:164)
    at com.google.appengine.tools.util.Parser$ParseResult.applyArgs(Parser.java:48)
    at com.google.appengine.tools.development.DevAppServerMain.<init>(DevAppServerMain.java:113)
    at com.google.appengine.tools.development.DevAppServerMain.main(DevAppServerMain.java:89)

So it seems the method java.util.Collections.newSetFromMap cannot be found, and indeed it does not exist in Java 1.5: http://download.oracle.com/javase/1.5.0/docs/api/java/util/Collections.html

But it does exist in Java 1.6: http://download.oracle.com/javase/6/docs/api/java/util/Collections.html#newSetFromMap(java.util.Map)

This is a little confusing because the Google App Engine is for Java 1.5, or at least it appears this way from looking at the plugin directory containing the SDK:

eclipse/plugins/com.google.appengine.eclipse.sdkbundle_1.5.1.r36v201106211634

I'm unsure about why I'm getting this error when I've followed the instructions.

SOLUTION

@kisp - thanks that set me on my way to solving the problem.

I have two versions of Java (1.5 and 1.6) installed on my Ubuntu machine:

/usr/lib/jvm/java-6-sun

and

/usr/lib/jvm/java-1.5.0-sun

I had only told Eclipse about Java 1.5. I needed to tell it about 1.6. To do this, open Eclipse:

Window > Preferences > Java > Installed JREs > Add

JRE home should just point to the directory Java is installed to, for me this is:

/usr/lib/jvm/java-6-sun-1.6.0.24

JRE name is defaults to a sensible value.

Once this has been added you can either set it as a the workspace default or set project specific settings. Right click on the project in Package Explorer:

Properties > Java Compiler >  Enable project specific settings

You should see your newly added Java version in the drop down menu.

The plugin version does not correspond to java version.

I have 1.4.2 installed and using java 1.6

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