" java.lang.NoSuchMethodError"使用Spreadsheet Service时会抛出异常

时间:2014-07-18 13:19:36

标签: java google-api google-spreadsheet-api

我使用以下代码来获取电子表格并打印工作表标题。

import com.google.gdata.client.spreadsheet.*;
import com.google.gdata.data.spreadsheet.*;
import com.google.gdata.util.*;

import java.io.IOException;
import java.net.*;
import java.util.*;

public class MySpreadsheetIntegration {
    public static void main(String[] args)
            throws AuthenticationException, MalformedURLException, IOException, ServiceException {
        SpreadsheetService service =
                new SpreadsheetService("MySpreadsheetIntegration-v1");

        URL SPREADSHEET_FEED_URL = new URL(
                "spreadsheet URL");

        SpreadsheetFeed feed = service.getFeed(SPREADSHEET_FEED_URL, SpreadsheetFeed.class);
        List<SpreadsheetEntry> spreadsheets = feed.getEntries();

        for (SpreadsheetEntry spreadsheet : spreadsheets) {
            // Print the title of this spreadsheet to the screen
            System.out.println(spreadsheet.getTitle().getPlainText());
        }

    }
}

但我得到的例外情况如下:

Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.collect.ImmutableSet.copyOf([Ljava/lang/Object;)Lcom/google/common/collect/ImmutableSet;
    at com.google.gdata.wireformats.AltFormat$Builder.setAcceptableTypes(AltFormat.java:399)
    at com.google.gdata.wireformats.AltFormat$Builder.setAcceptableXmlTypes(AltFormat.java:387)
    at com.google.gdata.wireformats.AltFormat.<clinit>(AltFormat.java:49)
    at com.google.gdata.client.Service.<clinit>(Service.java:558)
    at myPackage.MySpreadsheetIntegration.main(MySpreadsheetIntegration.java:23)
    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:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

我没有找到任何导致此错误的原因,请帮我解决问题以获取电子表格数据。

我正在使用以下主罐:

gdata-spreadsheet-3.0
mailapi.jar
gdata-core-1.0 

1 个答案:

答案 0 :(得分:0)

com.google.common.collectGuava: Google Core Libraries for Java 1.6+的一部分。您可能需要下载并安装它们...... guava-17.0.jar似乎是番石榴罐的最新版本......