【发布时间】:2014-01-21 10:33:38
【问题描述】:
在尝试使用 SpreadsheetService 类访问 Google 电子表格时,我收到了ExceptionInInitializerError。
以下是我的代码:
我已在文件中包含以下 jar 文件
gdata-client-1.0.jar
gdata-client-meta-1.0.jar
gdata-core-1.0.jar
gdata-spreadsheet-3.0.jar
gdata-spreadsheet-meta-3.0.jar
google-api-client-1.12.0-beta.jar
google-api-client-android-1.12.0-beta.jar
google-http-client-1.12.0-beta.jar
google-http-client-android-1.12.0-beta.jar
google-oauth-client-1.12.0-beta.jar
gson-2.1.jar
guava-13.0.1.jar
jackson-core-asl-1.9.9.jar
jsr305-1.3.9.jar
protobuf-java-2.4.1.jar
代码如下:
SpreadsheetService service = new SpreadsheetService("ContactsApp");// Exception occured here
service.setProtocolVersion(SpreadsheetService.Versions.V3);
try {
service.setUserCredentials("abcd@gmail.com","pwd1234");
} catch (Exception e) {
e.printStackTrace();
}
ArrayList<ContactsModel> list = new ArrayList<ContactsModel>();
try {
String url=
"https://spreadsheets.google.com/feeds/list/0AsaDhyyXNaFSdDJ2VUxtVGVWN1Yza1loU1RPVVU3OFE/default/public/values";
// turn the string into a URL
URL urlString = new URL(url);
// You could substitute a cell feed here in place of
// the list feed
ListFeed feed = service.getFeed(urlString, ListFeed.class);
for (ListEntry entry : feed.getEntries()) {
ContactsModel contact = new ContactsModel();
CustomElementCollection elements = entry.getCustomElements();
contact.EmpID = elements.getValue("Emp Id");
contact.Name = elements.getValue("Name");
contact.personalEmail = elements.getValue("personal email");
contact.workEmail = elements.getValue("work email");
contact.emergencyContact = elements.getValue("Emergency Contact");
contact.relation = elements.getValue("Relation");
list.add(contact);
}
} catch (IOException e) {
e.printStackTrace();
} catch (ServiceException e) {
e.printStackTrace();
}
【问题讨论】:
-
错误在哪一行? .. 它还需要一个应用程序风格的密码,而不是你的真实 ID 和密码。
标签: android google-sheets google-spreadsheet-api