2015-10-14 86 views
0
當我運行我的代碼

有這樣的錯誤:在線程ClassCastException異常谷歌電子表格

異常「主要」 java.lang.ClassCastException:com.google.gdata.data.TextContent不能轉換爲com.google.gdata。 data.OutOfLineContent

這是該行的代碼錯誤:URL listFeedUrl = worksheet.getListFeedUrl();

我想檢索基於列表的飼料,但是有這樣的錯誤!

幫幫我。請!!!

我的課是:

package it.unical.mat.google_data; 
import android.support.multidex.MultiDex; 

import com.google.gdata.client.authn.oauth.*; 
import com.google.gdata.client.spreadsheet.*; 
import com.google.gdata.data.*; 
import com.google.gdata.data.batch.*; 
import com.google.gdata.data.spreadsheet.*; 
import com.google.gdata.util.*; 

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

    public class MySpreadsheetIntegration { 
     public static void main(String[] args) 
         throws AuthenticationException, MalformedURLException, IOException,   ServiceException{ 

SpreadsheetService service = 
     new SpreadsheetService("MySpreadsheetIntegration-v1"); 

// TODO: Authorize the service object for a specific user (see other sections) 

// Define the URL to request. This should never change. 
URL SPREADSHEET_FEED_URL = new URL(
     "https://spreadsheets.google.com/feeds/worksheets/api-key-here/public/full"); 

// Make a request to the API and get all spreadsheets. 
SpreadsheetFeed feed = service.getFeed(SPREADSHEET_FEED_URL, 
     SpreadsheetFeed.class); 
List<SpreadsheetEntry> spreadsheets = feed.getEntries(); 

if (spreadsheets.size() == 0) { 
    // TODO: There were no spreadsheets, act accordingly. 
} 

// TODO: Choose a spreadsheet more intelligently based on your 
// app's needs. 
SpreadsheetEntry spreadsheet = spreadsheets.get(0); 
System.out.println(spreadsheet.getTitle().getPlainText()); 

// Get the first worksheet of the first spreadsheet. 
// TODO: Choose a worksheet more intelligently based on your 
// app's needs. 
WorksheetFeed worksheetFeed = service.getFeed(
     spreadsheet.getWorksheetFeedUrl(), WorksheetFeed.class); 
List<WorksheetEntry> worksheets = worksheetFeed.getEntries(); 
WorksheetEntry worksheet = worksheets.get(0); 

// Fetch the list feed of the worksheet. 
URL listFeedUrl = worksheet.getListFeedUrl(); 
ListFeed listFeed = service.getFeed(listFeedUrl, ListFeed.class); 

// Iterate through each row, printing its cell values. 
for (ListEntry row : listFeed.getEntries()) { 
    // Print the first column's cell value 
    System.out.print(row.getTitle().getPlainText() + "\t"); 
    // Iterate over the remaining columns, and print each cell value 
    for (String tag : row.getCustomElements().getTags()) { 
     System.out.print(row.getCustomElements().getValue(tag) + "\t"); 
    } 
    System.out.println(); 
} 



System.out.println("ok!"); 
} 

}

回答

0

我覺得URL HAST是:

https://spreadsheets.google.com/feeds/spreadsheets/abc/public/full

...根據這個網站:

http://www.solutionoferror.com/java/outoflinecontent-exception-in-java-google-gdata-spreadsheet-library-169798.asp

希望這有助於!順便說一句:下次你應該從你的問題刪除您的API密鑰;)

編輯:我https://spreadsheets.google.com/feeds/spreadsheets/private/full返回一個好的結果的URL,但你有第一次使用SpreadsheetService登錄:

service.setUserCredentials("user", "pwd"); 
+1

如果我使用您的URL tipe有此錯誤:線程「main」com.google.gdata.util.InvalidEntryException中的異常:錯誤請求 VALUE divisibilitàsconosciuto。爲什麼? –

+0

你用鑰匙取代了「abc」嗎? – Friwi

+0

當然,我的電子表格是公開的! –