2014-07-18 41 views
0

我正在使用以下代碼來獲取電子表格並打印表格的標題。使用電子表格服務引發「java.lang.NoSuchMethodError」異常

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 

回答