【发布时间】:2015-10-14 15:34:14
【问题描述】:
当我运行我的代码时出现此错误:
线程“main”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!");
}
}
【问题讨论】:
标签: java android spreadsheet feed worksheet