我曾尝试使用此代码(正如我在教程中看到的那样)
Calendar cal = Calendar.getInstance();
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra("beginTime", dateStart.getTime());
intent.putExtra("allDay", false);
intent.putExtra("rrule", "FREQ=DAILY");
intent.putExtra("endTime", dateEnd.getTime());
intent.putExtra("hasAlarm", 1);
startActivity(intent);
在 android 中的集成日历上添加事件
但是正如我所写的那样,就行了一个 NullPointerException 错误
startActivity(intent);
有了这个堆栈
07-17 19:12:05.469: W/System.err(30939): java.lang.NullPointerException
07-17 19:12:05.469: W/System.err(30939): at android.app.Activity.startActivityForResult(Activity.java:2827)
07-17 19:12:05.469: W/System.err(30939): at android.app.Activity.startActivity(Activity.java:2933)
07-17 19:12:05.469: W/System.err(30939): at myapplication.beachparty.utility.MyUtility.addEventToCalendar(MyUtility.java:44)
07-17 19:12:05.469: W/System.err(30939): at myapplication.beachparty.it.PartyDetails$2.onClick(PartyDetails.java:114)
07-17 19:12:05.469: W/System.err(30939): at android.view.View.performClick(View.java:2485)
07-17 19:12:05.479: W/System.err(30939): at android.view.View$PerformClick.run(View.java:9080)
07-17 19:12:05.479: W/System.err(30939): at android.os.Handler.handleCallback(Handler.java:587)
07-17 19:12:05.499: W/System.err(30939): at android.os.Handler.dispatchMessage(Handler.java:92)
07-17 19:12:05.499: W/System.err(30939): at android.os.Looper.loop(Looper.java:130)
07-17 19:12:05.499: W/System.err(30939): at android.app.ActivityThread.main(ActivityThread.java:3687)
07-17 19:12:05.499: W/System.err(30939): at java.lang.reflect.Method.invokeNative(Native Method)
07-17 19:12:05.499: W/System.err(30939): at java.lang.reflect.Method.invoke(Method.java:507)
07-17 19:12:05.499: W/System.err(30939): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
07-17 19:12:05.499: W/System.err(30939): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
07-17 19:12:05.499: W/System.err(30939): at dalvik.system.NativeStart.main(Native Method)
07-17 19:12:07.069: W/System.err(30939): java.lang.NullPointerException
07-17 19:12:07.069: W/System.err(30939): at android.app.Activity.startActivityForResult(Activity.java:2827)
07-17 19:12:07.069: W/System.err(30939): at android.app.Activity.startActivity(Activity.java:2933)
07-17 19:12:07.069: W/System.err(30939): at myapplication.beachparty.utility.MyUtility.addEventToCalendar(MyUtility.java:44)
07-17 19:12:07.069: W/System.err(30939): at myapplication.beachparty.it.PartyDetails$3.onClick(PartyDetails.java:128)
07-17 19:12:07.069: W/System.err(30939): at android.view.View.performClick(View.java:2485)
07-17 19:12:07.069: W/System.err(30939): at android.view.View$PerformClick.run(View.java:9080)
07-17 19:12:07.069: W/System.err(30939): at android.os.Handler.handleCallback(Handler.java:587)
07-17 19:12:07.069: W/System.err(30939): at android.os.Handler.dispatchMessage(Handler.java:92)
07-17 19:12:07.069: W/System.err(30939): at android.os.Looper.loop(Looper.java:130)
07-17 19:12:07.069: W/System.err(30939): at android.app.ActivityThread.main(ActivityThread.java:3687)
07-17 19:12:07.069: W/System.err(30939): at java.lang.reflect.Method.invokeNative(Native Method)
07-17 19:12:07.069: W/System.err(30939): at java.lang.reflect.Method.invoke(Method.java:507)
07-17 19:12:07.069: W/System.err(30939): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
07-17 19:12:07.079: W/System.err(30939): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
07-17 19:12:07.079: W/System.err(30939): at dalvik.system.NativeStart.main(Native Method)
dateStart
广告
dateEnd
是
Date
指示事件的日期、嘴巴、年份和时间的对象
我也尝试过改变这些行
intent.putExtra("beginTime", cal.getTimeInMillis());
和
intent.putExtra("endTime", cal.getTimeInMillis()+60*60*1000);
怎么了?
注意我已经在模拟器和三星 Galaxy 上尝试过代码。并使用 API 级别 10 (GingerBread)