【问题标题】:ClassCastException google spreadsheetClassCastException 谷歌电子表格
【发布时间】: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


    【解决方案1】:

    我认为 URL 必须是:

    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 密钥;)

    编辑:对我来说,URL https://spreadsheets.google.com/feeds/spreadsheets/private/full 返回一个很好的结果,但你必须先使用 SpreadsheetService 登录:

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

    【讨论】:

    • 如果我使用您的 URL 提示出现此错误:线程“主”com.google.gdata.util.InvalidEntryException 中的异常:错误请求值 di visibilità sconosciuto。为什么?
    • 您是否将“abc”替换为您的密钥?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多