Main menu

How to solve an InvalidEntryException when working with Google's Spreadsheet API

I am fiddling with Google's Spreadsheet API and their Java library and sample code. The documentation in some areas of this is not pretty and while the library is doing a good job of hiding the specifics of the underlying GData protocol, it's giving me some troubles now and again. After running into a com.google.gdata.util.InvalidEntryException when creating a new TableEntry, I tried searching for a solution but did not find one. So I thought I would share it here. My specific exception was: 

   com.google.gdata.util.InvalidEntryException: Bad Request
   [Line 1, Column 496, element entry] Required extension element 
   http://schemas.google.com/spreadsheets/2006:header not found.

The solution was simple enough (and in fact the docs mention this): on your new entry you have to set the header, i.e. call

   yourNewSpreadhsheetEntry.setHeader(new Header(1))

or whatever you want your header to be before trying to insert() it into the table entries feed. So, generally speaking, if you get an "InvalidEntryException: Bad Request" look for the element name that is given in the error message (in this example it was "header", but it could also be "worksheet" etc.) and then make sure you call the appropriate setX() method, where X is Header, Worksheet etc.

Hope this helps.

 

© 2011 Stefan Ukena.