java.lang.ClassCastException:com.google.gdata.data.TextContent无法强制转换为com.google.gdata.data.OutOfLineContent

mc_*_*rad 10 java android spreadsheet worksheet feed

我会在一个网络中滑动所有的细胞,但我不解决.我的代码是:

SpreadsheetService service = new SpreadsheetService("MyApp");
   try{
       URL SPREADSHEET_URL = new URL("https://spreadsheets.google.com/feeds/worksheets/1-8ATDLTqmzo4QCQijeJ_swZAcmsh/public/full");
       SpreadsheetFeed feed = service.getFeed(SPREADSHEET_URL,SpreadsheetFeed.class);
       List<SpreadsheetEntry> spreadsheets = feed.getEntries();
       if (spreadsheets.size() == 0){
           System.out.println("NO SPREADSHEET");
       }

      for(int i = 0; i<spreadsheets.size(); i++){
          System.out.println(spreadsheets.get(i).getTitle().getPlainText());
      }
      List<WorksheetEntry> worksheets = spreadsheets.get(0).getWorksheets();
      for (int j=0; j<worksheets.size(); j++){
          System.out.println(worksheets.get(j).getTitle().getPlainText());
          URL listFeedUrl = worksheets.get(j).getListFeedUrl();
          ListFeed listFeed = service.getFeed(listFeedUrl,ListFeed.class);

      }
Run Code Online (Sandbox Code Playgroud)

它在最后一行报告的错误:

ListFeed listFeed = service.getFeed(listFeedUrl,ListFeed.class);
Run Code Online (Sandbox Code Playgroud)

当我编译我的代码有这个错误:

Exception in thread "main" java.lang.ClassCastException: com.google.gdata.data.TextContent cannot be cast to com.google.gdata.data.OutOfLineContent
at com.google.gdata.data.spreadsheet.WorksheetEntry.getFeedUrlString(WorksheetEntry.java:129)
at com.google.gdata.data.spreadsheet.WorksheetEntry.getListFeedUrl(WorksheetEntry.java:98)
at it.unical.mat.google_data.MySpreadsheetIntegration.main(MySpreadsheetIntegration.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Run Code Online (Sandbox Code Playgroud)

导入使用:

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;
Run Code Online (Sandbox Code Playgroud)

thi*_*_vm 2

下面提到了两种可能的解决方案

1.就像您看到调试控制台一样,Intellij Ide 的作用是调用反射。如果您尝试使用另一个 IDE 执行此执行,则可能有可能。(可能是 ecllipse)。正如我搜索到的这部分代码,它是 root方法异常的原因

com.google.gdata.data.spreadsheet.WorksheetEntry.getFeedUrlString(WorksheetEntry.java:129

    private String getFeedUrlString(String linkRelKind) {
    Version spreadsheetVersion = state.service.getProtocolVersion();

    if (spreadsheetVersion.isCompatible(SpreadsheetService.Versions.V1)) {
      Link feedLink = this.getLink(linkRelKind, Link.Type.ATOM);
      return feedLink.getHref();
    } else { // must be SpreadsheetService.Versions.V2; only 2 versions for now
      // List or Cells feed Url?
      if (linkRelKind.equals(Namespaces.LIST_LINK_REL)) {
        // the list feed is stored as a <content> tag
        return ((OutOfLineContent)(this.getContent())).getUri();
      } else { // it must be Namespaces.CELLS_LINK_REL
        // the cells feed is stored in the <link> tag
        Link feedLink = this.getLink(linkRelKind, Link.Type.ATOM);
        return feedLink.getHref();
      }
    }
  }
Run Code Online (Sandbox Code Playgroud)

下一个可能的解决方案可能是在编译期间

ListFeed listFeed = service.getFeed(listFeedUrl,ListFeed.class);
Run Code Online (Sandbox Code Playgroud)

在上面的行中,您尝试保存从您的服务获取“返回与特定提要 URL 关联的提要”的对象。

只需放置 try catch 块以从 url 获取列表提要,并在可能的情况下处理异常。

    try{
    service.getFeed(listFeedUrl,ListFeed.class);
    }
    catch(IOException e){
e.printStackTrace();
}
catch(ParseException e1){
e1.printStackTrace();
}
catch(ResourceNotFoundException e2){
e2.printStackTrace();
}
catch(ServiceException e3){
e3.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)

请也从该行调试出内联值。

希望它能帮助你。谢谢