1

I am writing a android app that need to insert event to Google Calendar. I run my app in my two android phone and thay are all success. However, some crash reports from others are received. They have null pointer exception in the last line of the following code.

(BTW, I have already handled two different URIs of google calendar by following Is there a way to access the calendar's entries without using gdata-java-client?)

Entire source code file: http://gonow.no-ip.org/hkpl/GoogleCalendar.java

I call function addEvent in another class by this

GoogleCalendar.addEvent(getContentResolver(),EVENT_TITLE,CONTENT);

Extracted:

ContentValues event = new ContentValues();
event.put("title", title);
event.put("description", description);
event.put("calendar_id",calId);      
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.DAY_OF_MONTH, 1);     
long start = cal.getTime().getTime();
event.put("dtstart", start);        
cal.add(Calendar.DAY_OF_MONTH, 1);  
long end = cal.getTime().getTime();        
event.put("dtend", end);        
event.put("hasAlarm",1); 
event.put("allDay", 1);           
Uri newEvent = cr.insert(Uri.parse(calanderEventURL), event); <-- exception here

Crash report here

java.lang.RuntimeException: An error occured while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:200) at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274) at java.util.concurrent.FutureTask.setException(FutureTask.java:125) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581) at java.lang.Thread.run(Thread.java:1019) Caused by: java.lang.NullPointerException at android.os.Parcel.readException(Parcel.java:1328) at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:160) at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:114) at android.content.ContentProviderProxy.insert(ContentProviderNative.java:408) at android.content.ContentResolver.insert(ContentResolver.java:604) at ming.hkpl.GoogleCalendar.addEvent(GoogleCalendar.java:93)

Community
  • 1
  • 1
Bear
  • 5,138
  • 5
  • 50
  • 80

1 Answers1

1

In general, use the following process:

  • Find the line number of the failure in the bottom of the stack trace with the company namespace (ming.hkpl.GoogleCalendar.addEvent)
  • Go to the line number of the file mentioned in the stack trace in an IDE or text editor
    • Add a breakpoint
    • Compile the code
    • Run jdb OR
  • Add a print statement to the previous line, printing the variable referenced in the line that throws an error. For example:

    System.out.println("Hi");
    System.out.println(driver);
    
  • Rebuild the code

References

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265