【问题标题】:"java.lang.NoSuchMethodError" exception is thrown on using Spreadsheet Service使用电子表格服务引发“java.lang.NoSuchMethodError”异常
【发布时间】:2014-07-18 13:19:35
【问题描述】:

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

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 

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

    • 添加这个jar后,没有抛出上述异常。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-01
    • 1970-01-01
    • 2012-06-21
    • 2017-03-03
    相关资源
    最近更新 更多