Note that there are some explanatory texts on larger screens.

plurals
  1. PONullPointerException while accessing the user's calendars list using Google Calendar API
    text
    copied!<p>I want to use the Google Calendar Api to pull the calendars, events, etc. I have the authentication token from the AccountManager class in android. So this way if a user is logged in the mobile using his google account, then i can easily retrieve the authentication token related to him. After thati do the following:</p> <pre><code> public Calendar useCalendarAPI(final String accessToken) { try{ HttpTransport transport = new NetHttpTransport(); AccessProtectedResource accessProtectedResource = new GoogleAccessProtectedResource(accessToken); Calendar.Builder builder = Calendar.builder(transport, new JacksonFactory()); builder.setApplicationName("My App Name"); builder.setHttpRequestInitializer(accessProtectedResource); JsonHttpRequestInitializer json = new JsonHttpRequestInitializer() { public void initialize(JsonHttpRequest request) { CalendarRequest calRequest = (CalendarRequest) request; calRequest.setKey(Common.API_KEY); calRequest.setOauthToken(accessToken); } }; builder.setJsonHttpRequestInitializer(json); Calendar calendarService= builder.build(); if(calendarService!= null) { return calendarService; } else return null; }catch (Exception e) { // TODO: handle exception e.getMessage(); } </code></pre> <p>After this i receive a Calendar object called as "calendarService".</p> <pre><code>public void getCalendarsList() { try { CalendarList calendarList = calendarService.calendarList().list().execute(); while (true) { for (CalendarListEntry calendarListEntry : calendarList.getItems()) { System.out.println(calendarListEntry.getSummary()); } String pageToken = calendarList.getNextPageToken(); if (pageToken != null &amp;&amp; !pageToken.equalsIgnoreCase("")) { calendarList = calendarService.calendarList().list().setPageToken(pageToken).execute(); } else { break; } } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } </code></pre> <p>This is copied from the Google Calendar API Documentation. Check this link <a href="http://code.google.com/apis/calendar/v3/using.html#retrieving_calendar_lists" rel="nofollow">here</a><br> But i am getting NullPointer Exception at the following line</p> <pre><code>CalendarList calendarList = calendarService.calendarList().list().execute(); </code></pre> <p>Please suggest something.</p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload