在 Google Data API 中执行联系人演示时出现运行时异常

发布于 2024-08-10 14:54:52 字数 2843 浏览 3 评论 0原文

我已经下载了 eclipse 的 google data API 插件。在处理联系人模板(Demo.java)时,

/* INSTRUCTION: This is a command line application. So please execute this template with the following arguments:

        arg[0] = username
        arg[1] = password
*/

/**
 * @author (Your Name Here)
 *
 */

import com.google.gdata.client.contacts.ContactsService;
import com.google.gdata.data.contacts.ContactEntry;
import com.google.gdata.data.contacts.ContactFeed;
import com.google.gdata.util.AuthenticationException;
import com.google.gdata.util.ServiceException;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

/**
 * This is a test template
 */

  public class Contacts {

    public static void main(String[] args) {

      try {

        // Create a new Contacts service
        ContactsService myService = new ContactsService("My Application");
        myService.setUserCredentials(args[0],args[1]);

        // Get a list of all entries
        URL metafeedUrl = new URL("http://www.google.com/m8/feeds/contacts/"+args[0]+"@gmail.com/base");
        System.out.println("Getting Contacts entries...\n");
        ContactFeed resultFeed = myService.getFeed(metafeedUrl, ContactFeed.class);
        List<ContactEntry> entries = resultFeed.getEntries();
        for(int i=0; i<entries.size(); i++) {
          ContactEntry entry = entries.get(i);
          System.out.println("\t" + entry.getTitle().getPlainText());
        }
        System.out.println("\nTotal Entries: "+entries.size());
      }
      catch(AuthenticationException e) {
        e.printStackTrace();
      }
      catch(MalformedURLException e) {
        e.printStackTrace();
      }
      catch(ServiceException e) {
        e.printStackTrace();
      }
      catch(IOException e) {
        e.printStackTrace();
      }
    }
  }

它已成功编译,但抛出此运行时异常(我提供正确的所需凭据作为参数)。

Exception in thread "main" 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:532)
    at Contacts.main(Contacts.java:36)
Caused by: java.lang.ClassNotFoundException: com.google.common.collect.Maps
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    ... 4 more

我确信,我错过了一些东西,但能够解决它。

I have downloaded the google data API plugin for eclipse. While dealing with the Contacts template (Demo.java)

/* INSTRUCTION: This is a command line application. So please execute this template with the following arguments:

        arg[0] = username
        arg[1] = password
*/

/**
 * @author (Your Name Here)
 *
 */

import com.google.gdata.client.contacts.ContactsService;
import com.google.gdata.data.contacts.ContactEntry;
import com.google.gdata.data.contacts.ContactFeed;
import com.google.gdata.util.AuthenticationException;
import com.google.gdata.util.ServiceException;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

/**
 * This is a test template
 */

  public class Contacts {

    public static void main(String[] args) {

      try {

        // Create a new Contacts service
        ContactsService myService = new ContactsService("My Application");
        myService.setUserCredentials(args[0],args[1]);

        // Get a list of all entries
        URL metafeedUrl = new URL("http://www.google.com/m8/feeds/contacts/"+args[0]+"@gmail.com/base");
        System.out.println("Getting Contacts entries...\n");
        ContactFeed resultFeed = myService.getFeed(metafeedUrl, ContactFeed.class);
        List<ContactEntry> entries = resultFeed.getEntries();
        for(int i=0; i<entries.size(); i++) {
          ContactEntry entry = entries.get(i);
          System.out.println("\t" + entry.getTitle().getPlainText());
        }
        System.out.println("\nTotal Entries: "+entries.size());
      }
      catch(AuthenticationException e) {
        e.printStackTrace();
      }
      catch(MalformedURLException e) {
        e.printStackTrace();
      }
      catch(ServiceException e) {
        e.printStackTrace();
      }
      catch(IOException e) {
        e.printStackTrace();
      }
    }
  }

it is getting compiled successfully, but throwing this runtime exception (i am providing correct required credentials as arguments).

Exception in thread "main" 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:532)
    at Contacts.main(Contacts.java:36)
Caused by: java.lang.ClassNotFoundException: com.google.common.collect.Maps
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    ... 4 more

I am sure, i am missing something, but enable to resolve it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无尽的现实 2024-08-17 14:54:52

您似乎缺少依赖项。下载此 google-collections 并将该 jar 添加到您的构建路径中。

You seem to be missing a dependency. Download this google-collections and add the jar to your build-path.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文