2

我在为 gdata java 库运行此示例代码时遇到问题:

import java.net.URL;
import com.google.gdata.client.Query;
import com.google.gdata.client.blogger.BloggerService;
import com.google.gdata.data.Feed;

public class AccessBloggerSample {

public static void main(String[] args) throws Exception {
   BloggerService service = new BloggerService("Testing-Blogger");
   service.setUserCredentials("tmerachli@gmail.com", "XXX");
   System.out.println("Google: " + BloggerService.getVersion());
   URL feedUrl = new URL("http://minhchaunyc.blogspot.com/feeds/posts/default ");
   Query query = new Query(feedUrl);
   System.out.println("service: ");
   Feed resultFeed = service.getFeed(query, Feed.class);
   System.out.println("blogs: " + resultFeed.getEntries().size());
   }
}

我收到以下错误:

java.lang.NoClassDefFoundError: com/google/common/collect/Maps
at com.google.gdata.wireformats.AltRegistry.<init>(AltRegistry.java:118)
at com.google.gdata.wireformats.AltRegistry.<init>(AltRegistry.java:100)
at com.google.gdata.client.Service.<clinit>(Service.java:555)
at AccessBloggerSample.main(AccessBloggerSample.java:23)
Caused by: java.lang.ClassNotFoundException: com.google.common.collect.Maps
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at com.google.gdata.wireformats.AltRegistry.<init>(AltRegistry.java:118)
at com.google.gdata.wireformats.AltRegistry.<init>(AltRegistry.java:100)
at com.google.gdata.client.Service.<clinit>(Service.java:555)
at AccessBloggerSample.main(AccessBloggerSample.java:23)
at __SHELL0.run(__SHELL0.java:6)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at bluej.runtime.ExecServer$3.run(ExecServer.java:724)`

任何想法为什么我得到这个?我正在通过 BlueJ 编译和运行我的代码,我将所有 jar 文件提取到 BlueJ 的 lib 目录中,并且代码编译。

4

1 回答 1

0

您需要将番石榴添加到您的 Java Build-Patproject:http ://code.google.com/p/guava-libraries/

于 2013-01-28T11:04:25.413 回答