线程以未捕获的异常退出(group = 0x41736e30)

时间:2016-02-20 19:39:11

标签: android google-calendar-api android-calendar

public class CreateEventTask extends AsyncTask<Void, Void, Void> {
    com.google.api.services.calendar.Calendar mService;
    java.util.Calendar calendar, calendar1;
    String EventTitle;
    String useremail;
    String location;

CreateEventTask(Calendar mService, String EvTitle, java.util.Calendar cal, java.util.Calendar cal1, String Uemail, String loc) {
        this.mService = mService;
        EventTitle = EvTitle;
        calendar = cal;
        calendar1 = cal1;
        useremail = Uemail;
        location = loc;
    }

@Override
protected Void doInBackground(Void... params) {
    addCalendarEvent();
    return null;
}

  public void addCalendarEvent() {
        Event event = new Event()
                .setSummary(EventTitle)
                .setLocation(location)
                .setDescription("My efforts.");

        DateTime startDateTime = new DateTime(calendar.getTime());
        EventDateTime start = new EventDateTime().setDateTime(startDateTime);
        event.setStart(start);

        DateTime endDateTime = new DateTime(calendar1.getTime());
        EventDateTime end = new EventDateTime().setDateTime(endDateTime);

        event.setEnd(end);
        Log.d("Event stored", event.getEnd().getDateTime().toString());
        String calendarId = "primary";
        try {
            mService.events().insert(calendarId, event).execute();
        } catch (IOException e) {
            e.printStackTrace();
        }

我的这段代码创建了一天的事件,没有任何错误 例如,如果在2016年3月4日存在一个事件   创建活动开始日期2016年3月3日至2016年3月5日 它提供以下例外请帮助

  02-21 00:31:54.534  14067-14187/com.example.meetingplanner W/dalvikvm﹕ threadid=13: thread exiting with uncaught exception (group=0x41736e30)
        02-21 00:31:54.544  14067-14187/com.example.meetingplanner E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #2
            Process: com.example.meetingplanner, PID: 14067
            java.lang.RuntimeException: An error occured while executing doInBackground()
                    at android.os.AsyncTask$3.done(AsyncTask.java:300)
                    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
                    at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
                    at java.util.concurrent.FutureTask.run(FutureTask.java:242)
                    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
                    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
                    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
                    at java.lang.Thread.run(Thread.java:864)
             Caused by: java.lang.NullPointerException
                    at com.example.meetingplanner.CreateEventTask.addCalendarEvent(CreateEventTask.java:52)
                    at com.example.meetingplanner.CreateEventTask.doInBackground(CreateEventTask.java:31)
                    at com.example.meetingplanner.CreateEventTask.doInBackground(CreateEventTask.java:13)
                    at android.os.AsyncTask$2.call(AsyncTask.java:288)
                    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
                    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
                    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
                    at java.lang.Thread.run(Thread.java:864)

2 个答案:

答案 0 :(得分:1)

有些东西是空的,你最好的办法是启动一个调试器,在addCalendarEvent第52行放一个断点,并检查一下。选项包括:

  • MSERVICE
  • mService.events()
  • mService.events()。insert(calendarId,event)

或者将其分成多行并检查是否无效。

答案 1 :(得分:0)

addCalendarEvent移至功能catch(Exception | IOException e ){e.printstacktrace();}的开头并使用exec(thing)