访问Google日历时出现空指针异常

时间:2021-11-30 15:44:16

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.

我正在编写一个需要将事件插入Google日历的Android应用程序。我在我的两个安卓手机中运行我的应用程序,但它们都取得了成功。但是,收到了其他人的一些崩溃报告。它们在以下代码的最后一行中具有空指针异常。

(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?)

(顺便说一句,我已经处理过两个不同的谷歌日历URI了,有没有办法在不使用gdata-java-client的情况下访问日历的条目?)

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

整个源代码文件:http://gonow.no-ip.org/hkpl/GoogleCalendar.java

I call function addEvent in another class by this

我在另一个类中调用函数addEvent

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)

java.lang.RuntimeException:在java.util.concurrent.FutureTask $ Sync.innerSetException(FutureTask.java:274)的android.os.AsyncTask $ 3.done(AsyncTask.java:200)上执行doInBackground()时发生错误java.util.concurrent.FutureTask的java.util.concurrent.FutureTask.setException(FutureTask.java:125)$ java.util.concurrent.FutureTask.run的$ Sync.innerRun(FutureTask.java:308)(FutureTask.java: 138)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)由android.database.DatabaseUtils.readExceptionFromParcel(在android.database.DatabaseUtils.readExceptionFromParcel上的android.d.d.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:160)的android.os.Parcel.readException(Parcel.java:1328)中的java.lang.NullPointerException引起: DatabaseUtils.java:114)在android.content.ContentResolver.insert(Conte)的android.content.ContentProviderProxy.insert(ContentProviderNative.java:408) ntResolver.java:604)在ming.hkpl.GoogleCalendar.addEvent(GoogleCalendar.java:93)

1 个解决方案

#1


0  

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)
  • 使用公司名称空间(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
    • 运行jdb OR

  • 在IDE或文本编辑器中转到堆栈跟踪中提到的文件的行号添加断点编译代码运行jdb OR

  • Add a print statement to the previous line, printing the variable referenced in the line that throws an error. For example:

    将print语句添加到上一行,打印引发错误的行中引用的变量。例如:

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

    重建代码

References

#1


0  

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)
  • 使用公司名称空间(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
    • 运行jdb OR

  • 在IDE或文本编辑器中转到堆栈跟踪中提到的文件的行号添加断点编译代码运行jdb OR

  • Add a print statement to the previous line, printing the variable referenced in the line that throws an error. For example:

    将print语句添加到上一行,打印引发错误的行中引用的变量。例如:

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

    重建代码

References