Altamash Shaikh
Altamash Shaikh

Reputation: 99

can anyone help me with reading data from google spread sheet in JAVA

I am trying below code for fetching data from google spreadsheet, but getting error.. can anyone help me with fetching data from google spreadsheet

public class gsheet 
{
    public static final String GOOGLE_ACCOUNT_USERNAME = "gmail-id";
    public static final String GOOGLE_ACCOUNT_PASSWORD = "password"; 
    public static final String SPREADSHEET_URL = "spread-sheet-URL";


      public static void main(String[] args) throws IOException, ServiceException
      {
        SpreadsheetService service = new SpreadsheetService("JAVA");
        service.setUserCredentials(GOOGLE_ACCOUNT_USERNAME, GOOGLE_ACCOUNT_PASSWORD);
        URL metafeedUrl = new URL(SPREADSHEET_URL);
        SpreadsheetEntry spreadsheet = service.getEntry(metafeedUrl, SpreadsheetEntry.class);
        URL listFeedUrl = ((WorksheetEntry) spreadsheet.getWorksheets().get(0)).getListFeedUrl();
        ListFeed feed = (ListFeed) service.getFeed(listFeedUrl, ListFeed.class);
        for(ListEntry entry : feed.getEntries())
        {
          System.out.println("new row");
          for(String tag : entry.getCustomElements().getTags())
          {
            System.out.println("     "+tag + ": " + entry.getCustomElements().getValue(tag));
          }

        }

      }

}

i am getting below error on running my code

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/Maps
    at com.google.gdata.wireformats.AltRegistry.<init>(AltRegistry.java:118)
    at com.google.gdata.wireformats.AltRegistry.<init>(AltRegistry.java:100)
    at com.google.gdata.client.Service.<clinit>(Service.java:555)
    at googlesheet.gsheet.main(gsheet.java:24)
Caused by: java.lang.ClassNotFoundException: com.google.common.collect.Maps
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 4 more

Upvotes: 0

Views: 50

Answers (1)

Jens
Jens

Reputation: 69505

You have to add google-collections.jar to your classpath.

Upvotes: 2

Related Questions