1

Eclipse用のGoogleデータ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

私は確かに何かが欠けていますが、それを解決できるようにします。

4

1 に答える 1

1

依存関係が欠落しているようです。このgoogle-collectionsをダウンロードして、ビルドパスにjarを追加します。

于 2009-11-08T11:49:16.147 に答える