2016-08-18 64 views
0

我想下面的代碼從谷歌電子表格中讀取數據,但得到讀取數據時出錯..任何人都可以幫助我從谷歌電子表格中取數據誰能幫助我從谷歌電子表格在JAVA

public class gsheet 
{ 
    public static final String GOOGLE_ACCOUNT_USERNAME = "gmail-id"; 
    public static final String GOOGLE_ACCOUNT_PASSWORD = "password"; 
    public static final String SPREADSHEET_URL = "spread-sheet-URL"; 


     public static void main(String[] args) throws IOException, ServiceException 
     { 
     SpreadsheetService service = new SpreadsheetService("JAVA"); 
     service.setUserCredentials(GOOGLE_ACCOUNT_USERNAME, GOOGLE_ACCOUNT_PASSWORD); 
     URL metafeedUrl = new URL(SPREADSHEET_URL); 
     SpreadsheetEntry spreadsheet = service.getEntry(metafeedUrl, SpreadsheetEntry.class); 
     URL listFeedUrl = ((WorksheetEntry) spreadsheet.getWorksheets().get(0)).getListFeedUrl(); 
     ListFeed feed = (ListFeed) service.getFeed(listFeedUrl, ListFeed.class); 
     for(ListEntry entry : feed.getEntries()) 
     { 
      System.out.println("new row"); 
      for(String tag : entry.getCustomElements().getTags()) 
      { 
      System.out.println("  "+tag + ": " + entry.getCustomElements().getValue(tag)); 
      } 

     } 

     } 

} 

我收到以下錯誤上運行我的代碼

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:555) 
    at googlesheet.gsheet.main(gsheet.java:24) 
Caused by: java.lang.ClassNotFoundException: com.google.common.collect.Maps 
    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) 
    ... 4 more 
+0

請發佈你得到的錯誤 – khakiout

回答

2

您必須添加google-collections.jar到類路徑中。

+0

仍然面臨問題 –

+0

@AltamashShaikh同樣的問題或者是其他類缺失? – Jens