Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.ClassCastException: com.google.gdata.data.TextContent cannot be cast to com.google.gdata.data.OutOfLineContent

I would slide all cell in a sheetwork , but I don't resolve. My code is:

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

      }

the error its reported at last line:

ListFeed listFeed = service.getFeed(listFeedUrl,ListFeed.class);

when I compile my code have this error:

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)

import used:

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;
like image 234
mc_marad Avatar asked Oct 14 '15 10:10

mc_marad


1 Answers

Two possible solution are mentioned below

1. As if you see the debug console there is role of Intellij Ide to invoke reflection .There may be possiblity if u try this execution with another IDE.(probably ecllipse).As what i search out this exact part of code which is root cause of your exception from the method

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();
      }
    }
  }

The next possible solution for this might be possile is that during compilation of

ListFeed listFeed = service.getFeed(listFeedUrl,ListFeed.class);

In above line you are trying to save object that get Returns the Feed associated with a particular feed URL from your service.

just put try catch block for getting List feed from urls and handle exception if possible.

    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();
}

please debug out the inline value from that line also .

Hope it would help you. Thanks

like image 127
this_is_om_vm Avatar answered Oct 12 '22 08:10

this_is_om_vm