You need to sign in to do that
Don't have an account?
Google Data API - Spreadsheet - Attempt to de-reference a null object exception
Hi,
we've been using the force.com google data api for some time now and a bug in the library did slowed us down in the beginning. We've been able to work around this problem but we think this should be fixed in the library.
To reproduce, create a spreadsheet document then set a value from a1 to g1.
Then run the included test code (dont forget to replace username, login and spreadsheet name with the proper info).
It will crash everytime when updating cell F1 with a null reference exception.
Keep in mind that this is test code only, cells update should be batched and better exception handling should be made but this is just some sample code to reproduce a problem we saw with the library!
SpreadSheetService service = new SpreadsheetService();
service.useClientLogin(username, login);
GoogleData sheets = service.getSpreadsheets();
//get spreadsheet
GoogleData feeda = service.getSpreadsheetsTitle(spreadsheetname)
xmldom.element ssheet = feeda.entries[0];
//get worksheet in spreadsheet
string workSheetFeedUrl = SpreadsheetService.getWorksheetFeedUrl(ssheet);
GoogleData worksheetsFeed = service.getFeed( workSheetFeedUrl );
GoogleData.Worksheet worksheet = new GoogleData.Worksheet( worksheetsFeed.entries[0] );
//get cell data from worksheet in spreadsheet
string cellFeedUrl = worksheet.getCellFeedUrl();
// specify range to avoid data overflow
GoogleData feed = service.getFeedRange( cellFeedUrl ,'A1:L1');
//get the cell values
list<GoogleData.Cell> cells = worksheet.cellFactory( feed.entries );
for (GoogleData.Cell cel : cells )
{
cel.content = '5';
service.updateCell(worksheet, cel);
}
//get the cell values
feed = service.getFeedRange( cellFeedUrl ,'M1:N1');
cells = worksheet.cellFactory( feed.entries );
for (GoogleData.Cell cel : cells )
{
if(cel.title == 'M1')
{
System.debug('CELL M1 is: '+cel.content);
}
}