10

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;
Vikrant Kashyap
  • 6,398
  • 3
  • 32
  • 52
mc_marad
  • 179
  • 1
  • 1
  • 10
  • post your error log with import statement – Rahul Chaudhary Oct 14 '15 at 13:03
  • @RahulChaudhary show up my edits – mc_marad Oct 14 '15 at 13:41
  • Actually in the implementation of WorksheetEntry you can see a downcasting on line 129: ((OutOfLineContent)(this.getContent())).getUri(). This is not permitted and that's why you have an ClassCastException – Stefano Vuerich Apr 27 '18 at 12:27
  • This is the same code mentioned in Google Sheets docs , Is there any alternate code to do this – Ashish Awasthi Apr 28 '18 at 05:32
  • @AshishAwasthi I would like to debug the issue, but the URL in OPs question is out of date and thus it's not possible anymore to reproduce this error. Can you provide a valid URL for testing purposes? – Max Vollmer Apr 28 '18 at 08:53
  • @MaxVollmer Here is the URL of spreasheet that I am try to access and add a row into it and if you say i can provide the whole code of Java class https://spreadsheets.google.com/feeds/worksheets/1G3VABou70MUbRzY4vHgiDME5JW5rfo7lrAr_hZyEawU/private/full – Ashish Awasthi Apr 28 '18 at 09:15
  • @AshishAwasthi The spreadsheet you are trying to access has "private/full" at the end. That means you have to be logged in to see it. So would work just fine if you point your browser to it but not so much if you run it from code. – Jeffrey Phillips Freeman May 01 '18 at 04:35
  • Thanks for help,but is not working on my code – Venki WAR May 01 '18 at 11:34

1 Answers1

2

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

this_is_om_vm
  • 608
  • 5
  • 23