问题描述
当我运行我的应用程序,以及I $上的一个按钮就强制关闭p $ PSS。我修好了我的Android清单,我无法发现问题。这里是logcat的:
03-07 23:48:53.035:D / dalvikvm(5457):GC_EXTERNAL_ALLOC释放43K,49%免费2797K / 5379K,1596K外部/ 2108K,暂停99ms
03-07 23:48:53.132:D / dalvikvm(5457):GC_EXTERNAL_ALLOC释放1K,49%免费2796K / 5379K,3471K外部/ 4335K,暂停为35ms
03-07 23:48:53.691:D / dalvikvm(5457):GC_EXTERNAL_ALLOC释放< 1K,48%免费2798K / 5379K,5048K外部/ 5580K,暂停53ms
03-07 23:48:54.281:D / dalvikvm(5457):GC_EXTERNAL_ALLOC释放< 1K,48%免费2799K / 5379K,8143K外部/ 8403K,暂停过48ms
03-07 23:48:55.996:D / AndroidRuntime(5457):关闭VM
03-07 23:48:55.996:W / dalvikvm(5457):主题ID = 1:螺纹未捕获的异常(组= 0x40015578)退出
03-07 23:48:56.039:E / AndroidRuntime(5457):致命异常:主要
03-07 23:48:56.039:E / AndroidRuntime(5457):android.content.ActivityNotFoundException:无法找到明确的活动类{izzy.n / izzy.n.main1};有你宣布你的AndroidManifest.xml这个活动?
03-07 23:48:56.039:E / AndroidRuntime(5457):在android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
03-07 23:48:56.039:E / AndroidRuntime(5457):在android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
03-07 23:48:56.039:E / AndroidRuntime(5457):在android.app.Activity.startActivityForResult(Activity.java:2827)
03-07 23:48:56.039:E / AndroidRuntime(5457):在android.app.Activity.startActivity(Activity.java:2933)
03-07 23:48:56.039:E / AndroidRuntime(5457):在izzy.n.IzzynActivity $ 2.onClick(IzzynActivity.java:31)
03-07 23:48:56.039:E / AndroidRuntime(5457):在android.view.View.performClick(View.java:2538)
03-07 23:48:56.039:E / AndroidRuntime(5457):在android.view.View $ PerformClick.run(View.java:9152)
03-07 23:48:56.039:E / AndroidRuntime(5457):在android.os.Handler.handleCallback(Handler.java:587)
03-07 23:48:56.039:E / AndroidRuntime(5457):在android.os.Handler.dispatchMessage(Handler.java:92)
03-07 23:48:56.039:E / AndroidRuntime(5457):在android.os.Looper.loop(Looper.java:130)
03-07 23:48:56.039:E / AndroidRuntime(5457):在android.app.ActivityThread.main(ActivityThread.java:3687)
03-07 23:48:56.039:E / AndroidRuntime(5457):在java.lang.reflect.Method.invokeNative(本机方法)
03-07 23:48:56.039:E / AndroidRuntime(5457):在java.lang.reflect.Method.invoke(Method.java:507)
03-07 23:48:56.039:E / AndroidRuntime(5457):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:842)
03-07 23:48:56.039:E / AndroidRuntime(5457):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
03-07 23:48:56.039:E / AndroidRuntime(5457):在dalvik.system.NativeStart.main(本机方法)
03-07 23:50:31.398:D / dalvikvm(5553):GC_EXTERNAL_ALLOC释放47K,49%免费2797K / 5379K,1596K外部/ 2108K,暂停21ms
03-07 23:50:31.457:D / dalvikvm(5553):GC_EXTERNAL_ALLOC释放1K,49%免费2796K / 5379K,3471K外部/ 4335K,暂停22毫秒
03-07 23:50:31.660:D / dalvikvm(5553):GC_EXTERNAL_ALLOC释放< 1K,48%免费2798K / 5379K,5048K外部/ 5580K,暂停25ms的
03-07 23:50:31.753:D / dalvikvm(5553):GC_EXTERNAL_ALLOC释放< 1K,48%免费2799K / 5379K,8143K外部/ 8403K,暂停20毫秒
03-07 23:50:41.910:D / AndroidRuntime(5553):关闭VM
03-07 23:50:41.910:W / dalvikvm(5553):主题ID = 1:螺纹未捕获的异常(组= 0x40015578)退出
03-07 23:50:41.933:E / AndroidRuntime(5553):致命异常:主要
03-07 23:50:41.933:E / AndroidRuntime(5553):android.content.ActivityNotFoundException:无法找到明确的活动类{izzy.n / izzy.n.main1};有你宣布你的AndroidManifest.xml这个活动?
03-07 23:50:41.933:E / AndroidRuntime(5553):在android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
03-07 23:50:41.933:E / AndroidRuntime(5553):在android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
03-07 23:50:41.933:E / AndroidRuntime(5553):在android.app.Activity.startActivityForResult(Activity.java:2827)
03-07 23:50:41.933:E / AndroidRuntime(5553):在android.app.Activity.startActivity(Activity.java:2933)
03-07 23:50:41.933:E / AndroidRuntime(5553):在izzy.n.IzzynActivity $ 2.onClick(IzzynActivity.java:31)
03-07 23:50:41.933:E / AndroidRuntime(5553):在android.view.View.performClick(View.java:2538)
03-07 23:50:41.933:E / AndroidRuntime(5553):在android.view.View $ PerformClick.run(View.java:9152)
03-07 23:50:41.933:E / AndroidRuntime(5553):在android.os.Handler.handleCallback(Handler.java:587)
03-07 23:50:41.933:E / AndroidRuntime(5553):在android.os.Handler.dispatchMessage(Handler.java:92)
03-07 23:50:41.933:E / AndroidRuntime(5553):在android.os.Looper.loop(Looper.java:130)
03-07 23:50:41.933:E / AndroidRuntime(5553):在android.app.ActivityThread.main(ActivityThread.java:3687)
03-07 23:50:41.933:E / AndroidRuntime(5553):在java.lang.reflect.Method.invokeNative(本机方法)
03-07 23:50:41.933:E / AndroidRuntime(5553):在java.lang.reflect.Method.invoke(Method.java:507)
03-07 23:50:41.933:E / AndroidRuntime(5553):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:842)
03-07 23:50:41.933:E / AndroidRuntime(5553):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
03-07 23:50:41.933:E / AndroidRuntime(5553):在dalvik.system.NativeStart.main(本机方法)
03-07 23:51:20.371:D / dalvikvm(5609):GC_EXTERNAL_ALLOC释放48K,49%免费2797K / 5379K,1596K外部/ 2108K,暂停97ms
03-07 23:51:20.503:D / dalvikvm(5609):GC_EXTERNAL_ALLOC释放1K,49%免费2796K / 5379K,3471K外部/ 4335K,暂停57ms
03-07 23:51:20.792:D / dalvikvm(5609):GC_EXTERNAL_ALLOC释放< 1K,48%免费2798K / 5379K,5048K外部/ 5580K,暂停24ms
03-07 23:51:21.039:D / dalvikvm(5609):GC_EXTERNAL_ALLOC释放< 1K,48%免费2799K / 5379K,8143K外部/ 8403K,暂停为65μs
03-07 23:51:26.679:D / AndroidRuntime(5609):关闭VM
03-07 23:51:26.679:W / dalvikvm(5609):主题ID = 1:螺纹未捕获的异常(组= 0x40015578)退出
03-07 23:51:26.714:E / AndroidRuntime(5609):致命异常:主要
03-07 23:51:26.714:E / AndroidRuntime(5609):android.content.ActivityNotFoundException:无法找到明确的活动类{izzy.n / izzy.n.main1};有你宣布你的AndroidManifest.xml这个活动?
03-07 23:51:26.714:E / AndroidRuntime(5609):在android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
03-07 23:51:26.714:E / AndroidRuntime(5609):在android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
03-07 23:51:26.714:E / AndroidRuntime(5609):在android.app.Activity.startActivityForResult(Activity.java:2827)
03-07 23:51:26.714:E / AndroidRuntime(5609):在android.app.Activity.startActivity(Activity.java:2933)
03-07 23:51:26.714:E / AndroidRuntime(5609):在izzy.n.IzzynActivity $ 2.onClick(IzzynActivity.java:31)
03-07 23:51:26.714:E / AndroidRuntime(5609):在android.view.View.performClick(View.java:2538)
03-07 23:51:26.714:E / AndroidRuntime(5609):在android.view.View $ PerformClick.run(View.java:9152)
03-07 23:51:26.714:E / AndroidRuntime(5609):在android.os.Handler.handleCallback(Handler.java:587)
03-07 23:51:26.714:E / AndroidRuntime(5609):在android.os.Handler.dispatchMessage(Handler.java:92)
03-07 23:51:26.714:E / AndroidRuntime(5609):在android.os.Looper.loop(Looper.java:130)
03-07 23:51:26.714:E / AndroidRuntime(5609):在android.app.ActivityThread.main(ActivityThread.java:3687)
03-07 23:51:26.714:E / AndroidRuntime(5609):在java.lang.reflect.Method.invokeNative(本机方法)
03-07 23:51:26.714:E / AndroidRuntime(5609):在java.lang.reflect.Method.invoke(Method.java:507)
03-07 23:51:26.714:E / AndroidRuntime(5609):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:842)
03-07 23:51:26.714:E / AndroidRuntime(5609):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
03-07 23:51:26.714:E / AndroidRuntime(5609):在dalvik.system.NativeStart.main(本机方法)
03-07 23:59:24.920:D / dalvikvm(5784):GC_EXTERNAL_ALLOC释放51K,49%免费2797K / 5379K,1596K外部/ 2108K,暂停54ms
03-07 23:59:25.104:D / dalvikvm(5784):GC_EXTERNAL_ALLOC释放1K,49%免费2796K / 5379K,3471K外部/ 4335K,暂停46ms
03-07 23:59:25.537:D / dalvikvm(5784):GC_EXTERNAL_ALLOC释放< 1K,48%免费2798K / 5379K,5048K外部/ 5580K,暂停24ms
03-07 23:59:25.846:D / dalvikvm(5784):GC_EXTERNAL_ALLOC释放< 1K,48%免费2799K / 5379K,8143K外部/ 8403K,暂停38ms
03-07 23:59:41.502:D / dalvikvm(5784):GC_EXTERNAL_ALLOC释放10K,48%免费2828K / 5379K,11785K外部/ 11958K,暂停25ms的
03-07 23:59:41.740:D / dalvikvm(5784):GC_EXTERNAL_ALLOC释放< 1K,48%免费2829K / 5379K,13363K外部/ 14068K,暂停25ms的
03-07 23:59:41.865:D / dalvikvm(5784):GC_EXTERNAL_ALLOC释放< 1K,48%免费2830K / 5379K,16457K外部/ 17091K,暂停20毫秒
03-07 23:59:42.607:D / AndroidRuntime(5784):关闭VM
03-07 23:59:42.607:W / dalvikvm(5784):主题ID = 1:螺纹未捕获的异常(组= 0x40015578)退出
03-07 23:59:42.783:E / AndroidRuntime(5784):致命异常:主要
03-07 23:59:42.783:E / AndroidRuntime(5784):了java.lang.RuntimeException:无法启动活动ComponentInfo {izzy.n / izzy.n.main1}:显示java.lang.NullPointerException
03-07 23:59:42.783:E / AndroidRuntime(5784):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
03-07 23:59:42.783:E / AndroidRuntime(5784):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
03-07 23:59:42.783:E / AndroidRuntime(5784):在android.app.ActivityThread.access $ 1500(ActivityThread.java:117)
03-07 23:59:42.783:E / AndroidRuntime(5784):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:935)
03-07 23:59:42.783:E / AndroidRuntime(5784):在android.os.Handler.dispatchMessage(Handler.java:99)
03-07 23:59:42.783:E / AndroidRuntime(5784):在android.os.Looper.loop(Looper.java:130)
03-07 23:59:42.783:E / AndroidRuntime(5784):在android.app.ActivityThread.main(ActivityThread.java:3687)
03-07 23:59:42.783:E / AndroidRuntime(5784):在java.lang.reflect.Method.invokeNative(本机方法)
03-07 23:59:42.783:E / AndroidRuntime(5784):在java.lang.reflect.Method.invoke(Method.java:507)
03-07 23:59:42.783:E / AndroidRuntime(5784):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:842)
03-07 23:59:42.783:E / AndroidRuntime(5784):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
03-07 23:59:42.783:E / AndroidRuntime(5784):在dalvik.system.NativeStart.main(本机方法)
03-07 23:59:42.783:E / AndroidRuntime(5784):因:显示java.lang.NullPointerException
03-07 23:59:42.783:E / AndroidRuntime(5784):在izzy.n.main1.populateCalendarSpinner(main1.java:62)
03-07 23:59:42.783:E / AndroidRuntime(5784):在izzy.n.main1.onCreate(main1.java:52)
03-07 23:59:42.783:E / AndroidRuntime(5784):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-07 23:59:42.783:E / AndroidRuntime(5784):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
03-07 23:59:42.783:E / AndroidRuntime(5784):11 ...更多
03-07 23:59:52.850:I /流程(5784):发送信号。 PID:5784 SIG:9
03-08 00:11:06.982:D / dalvikvm(6029):GC_EXTERNAL_ALLOC释放46K,49%免费2797K / 5379K,1596K外部/ 2108K,暂停29ms
03-08 00:11:07.033:D / dalvikvm(6029):GC_EXTERNAL_ALLOC释放1K,49%免费2796K / 5379K,3471K外部/ 4335K,暂停20毫秒
03-08 00:11:07.248:D / dalvikvm(6029):GC_EXTERNAL_ALLOC释放< 1K,48%免费2798K / 5379K,5048K外部/ 5580K,暂停21ms
03-08 00:11:07.350:D / dalvikvm(6029):GC_EXTERNAL_ALLOC释放< 1K,48%免费2799K / 5379K,8143K外部/ 8403K,暂停19ms
03-08 00:11:10.588:D / dalvikvm(6029):GC_EXTERNAL_ALLOC释放9K,48%免费2828K / 5379K,11785K外部/ 11958K,暂停100毫秒
03-08 00:11:11.068:D / dalvikvm(6029):GC_EXTERNAL_ALLOC释放1K,48%免费2829K / 5379K,13363K外部/ 14068K,暂停49ms
03-08 00:11:11.365:D / dalvikvm(6029):GC_EXTERNAL_ALLOC释放< 1K,48%免费2830K / 5379K,16457K外部/ 17091K,暂停47ms
03-08 00:11:11.736:D / AndroidRuntime(6029):关闭VM
03-08 00:11:11.736:W / dalvikvm(6029):主题ID = 1:螺纹未捕获的异常(组= 0x40015578)退出
03-08 00:11:11.752:E / AndroidRuntime(6029):致命异常:主要
03-08 00:11:11.752:E / AndroidRuntime(6029):了java.lang.RuntimeException:无法启动活动ComponentInfo {izzy.n / izzy.n.main1}:显示java.lang.NullPointerException
03-08 00:11:11.752:E / AndroidRuntime(6029):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
03-08 00:11:11.752:E / AndroidRuntime(6029):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
03-08 00:11:11.752:E / AndroidRuntime(6029):在android.app.ActivityThread.access $ 1500(ActivityThread.java:117)
03-08 00:11:11.752:E / AndroidRuntime(6029):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:935)
03-08 00:11:11.752:E / AndroidRuntime(6029):在android.os.Handler.dispatchMessage(Handler.java:99)
03-08 00:11:11.752:E / AndroidRuntime(6029):在android.os.Looper.loop(Looper.java:130)
03-08 00:11:11.752:E / AndroidRuntime(6029):在android.app.ActivityThread.main(ActivityThread.java:3687)
03-08 00:11:11.752:E / AndroidRuntime(6029):在java.lang.reflect.Method.invokeNative(本机方法)
03-08 00:11:11.752:E / AndroidRuntime(6029):在java.lang.reflect.Method.invoke(Method.java:507)
03-08 00:11:11.752:E / AndroidRuntime(6029):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:842)
03-08 00:11:11.752:E / AndroidRuntime(6029):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
03-08 00:11:11.752:E / AndroidRuntime(6029):在dalvik.system.NativeStart.main(本机方法)
03-08 00:11:11.752:E / AndroidRuntime(6029):因:显示java.lang.NullPointerException
03-08 00:11:11.752:E / AndroidRuntime(6029):在izzy.n.main1.populateCalendarSpinner(main1.java:62)
03-08 00:11:11.752:E / AndroidRuntime(6029):在izzy.n.main1.onCreate(main1.java:52)
03-08 00:11:11.752:E / AndroidRuntime(6029):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-08 00:11:11.752:E / AndroidRuntime(6029):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
03-08 00:11:11.752:E / AndroidRuntime(6029):11 ...更多
03-08 00:16:11.924:I /流程(6029):发送信号。 PID:6029 SIG:9
03-08 00:16:14.525:D / dalvikvm(6173):GC_EXTERNAL_ALLOC释放10K,48%免费2828K / 5379K,11785K外部/ 11958K,暂停20毫秒
03-08 00:16:14.678:D / dalvikvm(6173):GC_EXTERNAL_ALLOC释放1K,48%免费2829K / 5379K,13363K外部/ 14068K,暂停22毫秒
03-08 00:16:14.779:D / dalvikvm(6173):GC_EXTERNAL_ALLOC释放< 1K,48%免费2829K / 5379K,16457K外部/ 17091K,暂停21ms
03-08 00:16:15.037:D / AndroidRuntime(6173):关闭VM
03-08 00:16:15.037:W / dalvikvm(6173):主题ID = 1:螺纹未捕获的异常(组= 0x40015578)退出
03-08 00:16:15.037:E / AndroidRuntime(6173):致命异常:主要
03-08 00:16:15.037:E / AndroidRuntime(6173):了java.lang.RuntimeException:无法启动活动ComponentInfo {izzy.n / izzy.n.main1}:显示java.lang.NullPointerException
03-08 00:16:15.037:E / AndroidRuntime(6173):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
03-08 00:16:15.037:E / AndroidRuntime(6173):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
03-08 00:16:15.037:E / AndroidRuntime(6173):在android.app.ActivityThread.access $ 1500(ActivityThread.java:117)
03-08 00:16:15.037:E / AndroidRuntime(6173):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:935)
03-08 00:16:15.037:E / AndroidRuntime(6173):在android.os.Handler.dispatchMessage(Handler.java:99)
03-08 00:16:15.037:E / AndroidRuntime(6173):在android.os.Looper.loop(Looper.java:130)
03-08 00:16:15.037:E / AndroidRuntime(6173):在android.app.ActivityThread.main(ActivityThread.java:3687)
03-08 00:16:15.037:E / AndroidRuntime(6173):在java.lang.reflect.Method.invokeNative(本机方法)
03-08 00:16:15.037:E / AndroidRuntime(6173):在java.lang.reflect.Method.invoke(Method.java:507)
03-08 00:16:15.037:E / AndroidRuntime(6173):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:842)
03-08 00:16:15.037:E / AndroidRuntime(6173):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
03-08 00:16:15.037:E / AndroidRuntime(6173):在dalvik.system.NativeStart.main(本机方法)
03-08 00:16:15.037:E / AndroidRuntime(6173):因:显示java.lang.NullPointerException
03-08 00:16:15.037:E / AndroidRuntime(6173):在izzy.n.main1.populateCalendarSpinner(main1.java:62)
03-08 00:16:15.037:E / AndroidRuntime(6173):在izzy.n.main1.onCreate(main1.java:52)
03-08 00:16:15.037:E / AndroidRuntime(6173):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-08 00:16:15.037:E / AndroidRuntime(6173):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
03-08 00:16:15.037:E / AndroidRuntime(6173):11 ...更多
下面是code为Android清单:
<?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=izzy.n
安卓版code =1
机器人:=的versionName1.0> <采用-SDK安卓的minSdkVersion =10/>
<使用许可权的android:NAME =android.permission.READ_CALENDAR>< /使用许可权>
<使用许可权的android:NAME =android.permission.WRITE_CALENDAR>< /使用许可权> <应用 机器人:图标=@绘制/ ic_launcher
机器人:标签=@字符串/ APP_NAME>
<活动
机器人:名字=izzy.n.IzzynActivity
机器人:标签=@字符串/ APP_NAME>
&所述;意图滤光器>
<作用机器人:名字=android.intent.action.MAIN/> <类机器人:名字=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT;
<活动
机器人:名字=izzy.n.notes
机器人:标签=@字符串/笔记>< /活性GT;
<活动
机器人:名字=izzy.n.calculator
机器人:标签=@字符串/计算器>< /活性GT;
<活动机器人:名字=izzy.n.main1
机器人:标签=@字符串/ APP_NAME>< /活性GT; < /用途>
< /清单>
和最后这里是main1.java:
类MyCalendar {
公共字符串名称;
公共字符串ID;
公共MyCalendar(字符串_name,字符串_id){
名称= _name;
ID = _id;
}
@覆盖
公共字符串的toString(){
返回名称;
}
}公共类MAIN1延伸活动{
/ ******************* ********************
* UI部分* /
私人微调m_spinner_calender;
私人按钮m_button_add;
私人按钮m_button_add2;
私人按钮m_button_getEvents;
私人TextView的m_text_event;
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
/ *获取日历列表,并填充视图* /
getCalendars();
populateCalendarSpinner();
populateAddBtn();
populateAddBtn2();
populateTextEvent();
populateGetEventsBtn();
}
私人无效populateCalendarSpinner(){
m_spinner_calender =(微调)this.findViewById(R.id.spinner_calendar);
ArrayAdapter l_arrayAdapter =新ArrayAdapter(this.getApplicationContext(),android.R.layout.simple_spinner_item,m_calendars);
l_arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
m_spinner_calender.setAdapter(l_arrayAdapter);
m_spinner_calender.setSelection(0);
m_spinner_calender.setOnItemSelectedListener(新AdapterView.OnItemSelectedListener(){
@覆盖
公共无效onItemSelected(适配器视图<> p_parent,查看p_view,
INT p_pos,长P_ID){
m_selectedCalendarId = m_calendars [(INT)P_ID] .ID;
}
@覆盖
公共无效onNothingSelected(适配器视图<>为arg0){}
});
}
私人无效populateAddBtn(){
m_button_add =(按钮)this.findViewById(R.id.button_add);
m_button_add.setOnClickListener(新View.OnClickListener(){
@覆盖
公共无效的onClick(视图v){
的addEvent();
}
});
}
私人无效populateAddBtn2(){
m_button_add2 =(按钮)this.findViewById(R.id.button_add2);
m_button_add2.setOnClickListener(新View.OnClickListener(){
@覆盖
公共无效的onClick(视图v){
addEvent2();
}
});
}
私人无效populateGetEventsBtn(){
m_button_getEvents =(按钮)findViewById(R.id.button_get_events);
m_button_getEvents.setOnClickListener(新View.OnClickListener(){
@覆盖
公共无效的onClick(视图v){
getLastThreeEvents();
}
});
}
私人无效populateTextEvent(){
m_text_event =(的TextView)findViewById(R.id.text_event);
字符串l_str =称号:roman10日历教程测试\\ n+
说明:这是日历API \\ n一个简单的测试+
eventLocation:@Home \\ n+
开始时间:+ getDateTimeStr(0)+\\ n+
结束时间:+ getDateTimeStr(30)+\\ n+
事件状态:确认\\ n+
一整天:无\\ n+
有报警:是\\ n;
m_text_event.setText(l_str);
}
/ ******************* ***************
*数据部分
* /
/ *检索可用日历列表* /
私人MyCalendar m_calendars [];
私人字符串m_selectedCalendarId =0;
私人无效getCalendars(){
的String [] = l_projection新的String [] {_ ID,显示名};
乌里l_calendars;
如果(Build.VERSION.SDK_INT> = 8){
l_calendars = Uri.parse(内容://com.android.calendar/calendars);
}其他{
l_calendars = Uri.parse(内容://日历/日历);
}
光标l_managedCursor = this.managedQuery(l_calendars,l_projection,NULL,NULL,NULL); //所有日历
//光标l_managedCursor = this.managedQuery(l_calendars,l_projection,选择= 1,NULL,NULL); //活动日历
如果(l_managedCursor.moveToFirst()){
m_calendars =新MyCalendar [l_managedCursor.getCount()];
串l_calName;
串l_calId;
INT l_cnt = 0;
INT l_nameCol = l_managedCursor.getColumnIndex(l_projection [1]);
INT l_idCol = l_managedCursor.getColumnIndex(l_projection [0]);
做{
l_calName = l_managedCursor.getString(l_nameCol);
l_calId = l_managedCursor.getString(l_idCol);
m_calendars [l_cnt] =新MyCalendar(l_calName,l_calId);
++ l_cnt;
}而(l_managedCursor.moveToNext());
}
}
/ *添加事件到日历* /
私人无效的addEvent(){
ContentValues l_event =新ContentValues();
l_event.put(CALENDAR_ID,m_selectedCalendarId);
l_event.put(称号,历roman10测试教程);
l_event.put(说明,这是日历API一个简单的测试);
l_event.put(eventLocation,@home);
l_event.put(DTSTART,返回System.currentTimeMillis());
l_event.put(DTEND,返回System.currentTimeMillis()+ 1800 * 1000);
l_event.put(allDay,0);
//状态:0〜试探性的; 1〜证实; 2〜取消
l_event.put(eventStatus,1);
// 0〜违约; 1〜保密; 2〜私有的; 3〜公
l_event.put(知名度,0);
// 0〜不透明,没有时序冲突是允许的; 1〜透明度,让调度重叠
l_event.put(透明度,0);
// 0〜虚假的; 1〜真
l_event.put(hasAlarm,1);
乌里l_eventUri;
如果(Build.VERSION.SDK_INT> = 8){
l_eventUri = Uri.parse(内容://com.android.calendar/events);
}其他{
l_eventUri = Uri.parse(内容://日历/事件);
}
乌里l_uri = this.getContentResolver()插入(l_eventUri,l_event)。
Log.v(++++++测试,l_uri.toString());
}
/ *通过意图添加事件,这不需要任何许可
*只要发送意图Android的Google日历
* http://www.openintents.org/en/uris*/
私人无效addEvent2(){
意图l_intent =新意图(Intent.ACTION_EDIT);
l_intent.setType(vnd.android.cursor.item /事件);
//l_intent.putExtra(\"calendar_id,m_selectedCalendarId); //这不起作用
l_intent.putExtra(称号,历roman10测试教程);
l_intent.putExtra(说明,这是日历API一个简单的测试);
l_intent.putExtra(eventLocation,@home);
l_intent.putExtra(BEGINTIME,返回System.currentTimeMillis());
l_intent.putExtra(结束时间,返回System.currentTimeMillis()+ 1800 * 1000);
l_intent.putExtra(allDay,0);
//状态:0〜试探性的; 1〜证实; 2〜取消
l_intent.putExtra(eventStatus,1);
// 0〜违约; 1〜保密; 2〜私有的; 3〜公
l_intent.putExtra(知名度,0);
// 0〜不透明,没有时序冲突是允许的; 1〜透明度,让调度重叠
l_intent.putExtra(透明度,0);
// 0〜虚假的; 1〜真
l_intent.putExtra(hasAlarm,1);
尝试{
startActivity(l_intent);
}赶上(例外五){
Toast.makeText(this.getApplicationContext(),对不起,不兼容的日历被发现!,Toast.LENGTH_LONG).show();
}
}
/ *得到的事件列表
* http://jimblackler.net/blog/?p=151*/
私人无效getLastThreeEvents(){
乌里l_eventUri;
如果(Build.VERSION.SDK_INT> = 8){
l_eventUri = Uri.parse(内容://com.android.calendar/events);
}其他{
l_eventUri = Uri.parse(内容://日历/事件);
}
的String [] = l_projection新的String [] {称号,DTSTART,DTEND};
光标l_managedCursor = this.managedQuery(l_eventUri,l_projection,CALENDAR_ID =+ m_selectedCalendarId,NULL,DTSTART DESC,DTEND DESC);
//光标l_managedCursor = this.managedQuery(l_eventUri,l_projection,NULL,NULL,NULL);
如果(l_managedCursor.moveToFirst()){
INT l_cnt = 0;
串l_title;
串l_begin;
串l_end;
StringBuilder的l_displayText =新的StringBuilder();
INT l_colTitle = l_managedCursor.getColumnIndex(l_projection [0]);
INT l_colBegin = l_managedCursor.getColumnIndex(l_projection [1]);
INT l_colEnd = l_managedCursor.getColumnIndex(l_projection [1]);
做{
l_title = l_managedCursor.getString(l_colTitle);
l_begin = getDateTimeStr(l_managedCursor.getString(l_colBegin));
l_end = getDateTimeStr(l_managedCursor.getString(l_colEnd));
l_displayText.append(l_title +\\ n+ l_begin +\\ n+ l_end +\\ n ---------------- \\ n);
++ l_cnt;
}而(l_managedCursor.moveToNext()及&放大器; l_cnt 3;);
m_text_event.setText(l_displayText.toString());
}
}
/ *********
*实用部分
* /
私有静态最后弦乐DATE_TIME_FORMAT =YYYY MMM DD,HH:MM:SS;
公共静态字符串getDateTimeStr(INT p_delay_min){
日历CAL = Calendar.getInstance();
SimpleDateFormat的SDF =新的SimpleDateFormat(DATE_TIME_FORMAT);
如果(p_delay_min == 0){
返回sdf.format(cal.getTime());
}其他{
日期l_time = cal.getTime();
l_time.setMinutes(l_time.getMinutes()+ p_delay_min);
返回sdf.format(l_time);
}
}
公共静态字符串getDateTimeStr(字符串p_time_in_millis){
SimpleDateFormat的SDF =新的SimpleDateFormat(DATE_TIME_FORMAT);
日期l_time =新的日期(的Long.parseLong(p_time_in_millis));
返回sdf.format(l_time);
}
}
在 populateCalendarSpinner()
方法的对象为null。请把尝试捕捉和调试。
您的日志显示
03-08 00:16:15.037:E / AndroidRuntime(6173):显示java.lang.NullPointerException:产生的原因
03-08 00:16:15.037:E / AndroidRuntime(6173):在izzy.n.main1.populateCalendarSpinner(main1.java:62)
03-08 00:16:15.037:E / AndroidRuntime(6173):在izzy.n.main1.onCreate(main1.java:52)
没有找到活动是旧的日志。你已经固定它。
When i run my app, and i press on a button it force closes. I fixed my Android manifest and i cannot find the problem. Here is the Logcat:
03-07 23:48:53.035: D/dalvikvm(5457): GC_EXTERNAL_ALLOC freed 43K, 49% free 2797K/5379K, external 1596K/2108K, paused 99ms
03-07 23:48:53.132: D/dalvikvm(5457): GC_EXTERNAL_ALLOC freed 1K, 49% free 2796K/5379K, external 3471K/4335K, paused 35ms
03-07 23:48:53.691: D/dalvikvm(5457): GC_EXTERNAL_ALLOC freed <1K, 48% free 2798K/5379K, external 5048K/5580K, paused 53ms
03-07 23:48:54.281: D/dalvikvm(5457): GC_EXTERNAL_ALLOC freed <1K, 48% free 2799K/5379K, external 8143K/8403K, paused 48ms
03-07 23:48:55.996: D/AndroidRuntime(5457): Shutting down VM
03-07 23:48:55.996: W/dalvikvm(5457): threadid=1: thread exiting with uncaught exception (group=0x40015578)
03-07 23:48:56.039: E/AndroidRuntime(5457): FATAL EXCEPTION: main
03-07 23:48:56.039: E/AndroidRuntime(5457): android.content.ActivityNotFoundException: Unable to find explicit activity class {izzy.n/izzy.n.main1}; have you declared this activity in your AndroidManifest.xml?
03-07 23:48:56.039: E/AndroidRuntime(5457): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
03-07 23:48:56.039: E/AndroidRuntime(5457): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
03-07 23:48:56.039: E/AndroidRuntime(5457): at android.app.Activity.startActivityForResult(Activity.java:2827)
03-07 23:48:56.039: E/AndroidRuntime(5457): at android.app.Activity.startActivity(Activity.java:2933)
03-07 23:48:56.039: E/AndroidRuntime(5457): at izzy.n.IzzynActivity$2.onClick(IzzynActivity.java:31)
03-07 23:48:56.039: E/AndroidRuntime(5457): at android.view.View.performClick(View.java:2538)
03-07 23:48:56.039: E/AndroidRuntime(5457): at android.view.View$PerformClick.run(View.java:9152)
03-07 23:48:56.039: E/AndroidRuntime(5457): at android.os.Handler.handleCallback(Handler.java:587)
03-07 23:48:56.039: E/AndroidRuntime(5457): at android.os.Handler.dispatchMessage(Handler.java:92)
03-07 23:48:56.039: E/AndroidRuntime(5457): at android.os.Looper.loop(Looper.java:130)
03-07 23:48:56.039: E/AndroidRuntime(5457): at android.app.ActivityThread.main(ActivityThread.java:3687)
03-07 23:48:56.039: E/AndroidRuntime(5457): at java.lang.reflect.Method.invokeNative(Native Method)
03-07 23:48:56.039: E/AndroidRuntime(5457): at java.lang.reflect.Method.invoke(Method.java:507)
03-07 23:48:56.039: E/AndroidRuntime(5457): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
03-07 23:48:56.039: E/AndroidRuntime(5457): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
03-07 23:48:56.039: E/AndroidRuntime(5457): at dalvik.system.NativeStart.main(Native Method)
03-07 23:50:31.398: D/dalvikvm(5553): GC_EXTERNAL_ALLOC freed 47K, 49% free 2797K/5379K, external 1596K/2108K, paused 21ms
03-07 23:50:31.457: D/dalvikvm(5553): GC_EXTERNAL_ALLOC freed 1K, 49% free 2796K/5379K, external 3471K/4335K, paused 22ms
03-07 23:50:31.660: D/dalvikvm(5553): GC_EXTERNAL_ALLOC freed <1K, 48% free 2798K/5379K, external 5048K/5580K, paused 25ms
03-07 23:50:31.753: D/dalvikvm(5553): GC_EXTERNAL_ALLOC freed <1K, 48% free 2799K/5379K, external 8143K/8403K, paused 20ms
03-07 23:50:41.910: D/AndroidRuntime(5553): Shutting down VM
03-07 23:50:41.910: W/dalvikvm(5553): threadid=1: thread exiting with uncaught exception (group=0x40015578)
03-07 23:50:41.933: E/AndroidRuntime(5553): FATAL EXCEPTION: main
03-07 23:50:41.933: E/AndroidRuntime(5553): android.content.ActivityNotFoundException: Unable to find explicit activity class {izzy.n/izzy.n.main1}; have you declared this activity in your AndroidManifest.xml?
03-07 23:50:41.933: E/AndroidRuntime(5553): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
03-07 23:50:41.933: E/AndroidRuntime(5553): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
03-07 23:50:41.933: E/AndroidRuntime(5553): at android.app.Activity.startActivityForResult(Activity.java:2827)
03-07 23:50:41.933: E/AndroidRuntime(5553): at android.app.Activity.startActivity(Activity.java:2933)
03-07 23:50:41.933: E/AndroidRuntime(5553): at izzy.n.IzzynActivity$2.onClick(IzzynActivity.java:31)
03-07 23:50:41.933: E/AndroidRuntime(5553): at android.view.View.performClick(View.java:2538)
03-07 23:50:41.933: E/AndroidRuntime(5553): at android.view.View$PerformClick.run(View.java:9152)
03-07 23:50:41.933: E/AndroidRuntime(5553): at android.os.Handler.handleCallback(Handler.java:587)
03-07 23:50:41.933: E/AndroidRuntime(5553): at android.os.Handler.dispatchMessage(Handler.java:92)
03-07 23:50:41.933: E/AndroidRuntime(5553): at android.os.Looper.loop(Looper.java:130)
03-07 23:50:41.933: E/AndroidRuntime(5553): at android.app.ActivityThread.main(ActivityThread.java:3687)
03-07 23:50:41.933: E/AndroidRuntime(5553): at java.lang.reflect.Method.invokeNative(Native Method)
03-07 23:50:41.933: E/AndroidRuntime(5553): at java.lang.reflect.Method.invoke(Method.java:507)
03-07 23:50:41.933: E/AndroidRuntime(5553): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
03-07 23:50:41.933: E/AndroidRuntime(5553): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
03-07 23:50:41.933: E/AndroidRuntime(5553): at dalvik.system.NativeStart.main(Native Method)
03-07 23:51:20.371: D/dalvikvm(5609): GC_EXTERNAL_ALLOC freed 48K, 49% free 2797K/5379K, external 1596K/2108K, paused 97ms
03-07 23:51:20.503: D/dalvikvm(5609): GC_EXTERNAL_ALLOC freed 1K, 49% free 2796K/5379K, external 3471K/4335K, paused 57ms
03-07 23:51:20.792: D/dalvikvm(5609): GC_EXTERNAL_ALLOC freed <1K, 48% free 2798K/5379K, external 5048K/5580K, paused 24ms
03-07 23:51:21.039: D/dalvikvm(5609): GC_EXTERNAL_ALLOC freed <1K, 48% free 2799K/5379K, external 8143K/8403K, paused 65ms
03-07 23:51:26.679: D/AndroidRuntime(5609): Shutting down VM
03-07 23:51:26.679: W/dalvikvm(5609): threadid=1: thread exiting with uncaught exception (group=0x40015578)
03-07 23:51:26.714: E/AndroidRuntime(5609): FATAL EXCEPTION: main
03-07 23:51:26.714: E/AndroidRuntime(5609): android.content.ActivityNotFoundException: Unable to find explicit activity class {izzy.n/izzy.n.main1}; have you declared this activity in your AndroidManifest.xml?
03-07 23:51:26.714: E/AndroidRuntime(5609): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
03-07 23:51:26.714: E/AndroidRuntime(5609): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
03-07 23:51:26.714: E/AndroidRuntime(5609): at android.app.Activity.startActivityForResult(Activity.java:2827)
03-07 23:51:26.714: E/AndroidRuntime(5609): at android.app.Activity.startActivity(Activity.java:2933)
03-07 23:51:26.714: E/AndroidRuntime(5609): at izzy.n.IzzynActivity$2.onClick(IzzynActivity.java:31)
03-07 23:51:26.714: E/AndroidRuntime(5609): at android.view.View.performClick(View.java:2538)
03-07 23:51:26.714: E/AndroidRuntime(5609): at android.view.View$PerformClick.run(View.java:9152)
03-07 23:51:26.714: E/AndroidRuntime(5609): at android.os.Handler.handleCallback(Handler.java:587)
03-07 23:51:26.714: E/AndroidRuntime(5609): at android.os.Handler.dispatchMessage(Handler.java:92)
03-07 23:51:26.714: E/AndroidRuntime(5609): at android.os.Looper.loop(Looper.java:130)
03-07 23:51:26.714: E/AndroidRuntime(5609): at android.app.ActivityThread.main(ActivityThread.java:3687)
03-07 23:51:26.714: E/AndroidRuntime(5609): at java.lang.reflect.Method.invokeNative(Native Method)
03-07 23:51:26.714: E/AndroidRuntime(5609): at java.lang.reflect.Method.invoke(Method.java:507)
03-07 23:51:26.714: E/AndroidRuntime(5609): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
03-07 23:51:26.714: E/AndroidRuntime(5609): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
03-07 23:51:26.714: E/AndroidRuntime(5609): at dalvik.system.NativeStart.main(Native Method)
03-07 23:59:24.920: D/dalvikvm(5784): GC_EXTERNAL_ALLOC freed 51K, 49% free 2797K/5379K, external 1596K/2108K, paused 54ms
03-07 23:59:25.104: D/dalvikvm(5784): GC_EXTERNAL_ALLOC freed 1K, 49% free 2796K/5379K, external 3471K/4335K, paused 46ms
03-07 23:59:25.537: D/dalvikvm(5784): GC_EXTERNAL_ALLOC freed <1K, 48% free 2798K/5379K, external 5048K/5580K, paused 24ms
03-07 23:59:25.846: D/dalvikvm(5784): GC_EXTERNAL_ALLOC freed <1K, 48% free 2799K/5379K, external 8143K/8403K, paused 38ms
03-07 23:59:41.502: D/dalvikvm(5784): GC_EXTERNAL_ALLOC freed 10K, 48% free 2828K/5379K, external 11785K/11958K, paused 25ms
03-07 23:59:41.740: D/dalvikvm(5784): GC_EXTERNAL_ALLOC freed <1K, 48% free 2829K/5379K, external 13363K/14068K, paused 25ms
03-07 23:59:41.865: D/dalvikvm(5784): GC_EXTERNAL_ALLOC freed <1K, 48% free 2830K/5379K, external 16457K/17091K, paused 20ms
03-07 23:59:42.607: D/AndroidRuntime(5784): Shutting down VM
03-07 23:59:42.607: W/dalvikvm(5784): threadid=1: thread exiting with uncaught exception (group=0x40015578)
03-07 23:59:42.783: E/AndroidRuntime(5784): FATAL EXCEPTION: main
03-07 23:59:42.783: E/AndroidRuntime(5784): java.lang.RuntimeException: Unable to start activity ComponentInfo{izzy.n/izzy.n.main1}: java.lang.NullPointerException
03-07 23:59:42.783: E/AndroidRuntime(5784): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
03-07 23:59:42.783: E/AndroidRuntime(5784): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
03-07 23:59:42.783: E/AndroidRuntime(5784): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-07 23:59:42.783: E/AndroidRuntime(5784): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
03-07 23:59:42.783: E/AndroidRuntime(5784): at android.os.Handler.dispatchMessage(Handler.java:99)
03-07 23:59:42.783: E/AndroidRuntime(5784): at android.os.Looper.loop(Looper.java:130)
03-07 23:59:42.783: E/AndroidRuntime(5784): at android.app.ActivityThread.main(ActivityThread.java:3687)
03-07 23:59:42.783: E/AndroidRuntime(5784): at java.lang.reflect.Method.invokeNative(Native Method)
03-07 23:59:42.783: E/AndroidRuntime(5784): at java.lang.reflect.Method.invoke(Method.java:507)
03-07 23:59:42.783: E/AndroidRuntime(5784): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
03-07 23:59:42.783: E/AndroidRuntime(5784): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
03-07 23:59:42.783: E/AndroidRuntime(5784): at dalvik.system.NativeStart.main(Native Method)
03-07 23:59:42.783: E/AndroidRuntime(5784): Caused by: java.lang.NullPointerException
03-07 23:59:42.783: E/AndroidRuntime(5784): at izzy.n.main1.populateCalendarSpinner(main1.java:62)
03-07 23:59:42.783: E/AndroidRuntime(5784): at izzy.n.main1.onCreate(main1.java:52)
03-07 23:59:42.783: E/AndroidRuntime(5784): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-07 23:59:42.783: E/AndroidRuntime(5784): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
03-07 23:59:42.783: E/AndroidRuntime(5784): ... 11 more
03-07 23:59:52.850: I/Process(5784): Sending signal. PID: 5784 SIG: 9
03-08 00:11:06.982: D/dalvikvm(6029): GC_EXTERNAL_ALLOC freed 46K, 49% free 2797K/5379K, external 1596K/2108K, paused 29ms
03-08 00:11:07.033: D/dalvikvm(6029): GC_EXTERNAL_ALLOC freed 1K, 49% free 2796K/5379K, external 3471K/4335K, paused 20ms
03-08 00:11:07.248: D/dalvikvm(6029): GC_EXTERNAL_ALLOC freed <1K, 48% free 2798K/5379K, external 5048K/5580K, paused 21ms
03-08 00:11:07.350: D/dalvikvm(6029): GC_EXTERNAL_ALLOC freed <1K, 48% free 2799K/5379K, external 8143K/8403K, paused 19ms
03-08 00:11:10.588: D/dalvikvm(6029): GC_EXTERNAL_ALLOC freed 9K, 48% free 2828K/5379K, external 11785K/11958K, paused 100ms
03-08 00:11:11.068: D/dalvikvm(6029): GC_EXTERNAL_ALLOC freed 1K, 48% free 2829K/5379K, external 13363K/14068K, paused 49ms
03-08 00:11:11.365: D/dalvikvm(6029): GC_EXTERNAL_ALLOC freed <1K, 48% free 2830K/5379K, external 16457K/17091K, paused 47ms
03-08 00:11:11.736: D/AndroidRuntime(6029): Shutting down VM
03-08 00:11:11.736: W/dalvikvm(6029): threadid=1: thread exiting with uncaught exception (group=0x40015578)
03-08 00:11:11.752: E/AndroidRuntime(6029): FATAL EXCEPTION: main
03-08 00:11:11.752: E/AndroidRuntime(6029): java.lang.RuntimeException: Unable to start activity ComponentInfo{izzy.n/izzy.n.main1}: java.lang.NullPointerException
03-08 00:11:11.752: E/AndroidRuntime(6029): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
03-08 00:11:11.752: E/AndroidRuntime(6029): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
03-08 00:11:11.752: E/AndroidRuntime(6029): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-08 00:11:11.752: E/AndroidRuntime(6029): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
03-08 00:11:11.752: E/AndroidRuntime(6029): at android.os.Handler.dispatchMessage(Handler.java:99)
03-08 00:11:11.752: E/AndroidRuntime(6029): at android.os.Looper.loop(Looper.java:130)
03-08 00:11:11.752: E/AndroidRuntime(6029): at android.app.ActivityThread.main(ActivityThread.java:3687)
03-08 00:11:11.752: E/AndroidRuntime(6029): at java.lang.reflect.Method.invokeNative(Native Method)
03-08 00:11:11.752: E/AndroidRuntime(6029): at java.lang.reflect.Method.invoke(Method.java:507)
03-08 00:11:11.752: E/AndroidRuntime(6029): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
03-08 00:11:11.752: E/AndroidRuntime(6029): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
03-08 00:11:11.752: E/AndroidRuntime(6029): at dalvik.system.NativeStart.main(Native Method)
03-08 00:11:11.752: E/AndroidRuntime(6029): Caused by: java.lang.NullPointerException
03-08 00:11:11.752: E/AndroidRuntime(6029): at izzy.n.main1.populateCalendarSpinner(main1.java:62)
03-08 00:11:11.752: E/AndroidRuntime(6029): at izzy.n.main1.onCreate(main1.java:52)
03-08 00:11:11.752: E/AndroidRuntime(6029): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-08 00:11:11.752: E/AndroidRuntime(6029): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
03-08 00:11:11.752: E/AndroidRuntime(6029): ... 11 more
03-08 00:16:11.924: I/Process(6029): Sending signal. PID: 6029 SIG: 9
03-08 00:16:14.525: D/dalvikvm(6173): GC_EXTERNAL_ALLOC freed 10K, 48% free 2828K/5379K, external 11785K/11958K, paused 20ms
03-08 00:16:14.678: D/dalvikvm(6173): GC_EXTERNAL_ALLOC freed 1K, 48% free 2829K/5379K, external 13363K/14068K, paused 22ms
03-08 00:16:14.779: D/dalvikvm(6173): GC_EXTERNAL_ALLOC freed <1K, 48% free 2829K/5379K, external 16457K/17091K, paused 21ms
03-08 00:16:15.037: D/AndroidRuntime(6173): Shutting down VM
03-08 00:16:15.037: W/dalvikvm(6173): threadid=1: thread exiting with uncaught exception (group=0x40015578)
03-08 00:16:15.037: E/AndroidRuntime(6173): FATAL EXCEPTION: main
03-08 00:16:15.037: E/AndroidRuntime(6173): java.lang.RuntimeException: Unable to start activity ComponentInfo{izzy.n/izzy.n.main1}: java.lang.NullPointerException
03-08 00:16:15.037: E/AndroidRuntime(6173): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
03-08 00:16:15.037: E/AndroidRuntime(6173): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
03-08 00:16:15.037: E/AndroidRuntime(6173): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-08 00:16:15.037: E/AndroidRuntime(6173): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
03-08 00:16:15.037: E/AndroidRuntime(6173): at android.os.Handler.dispatchMessage(Handler.java:99)
03-08 00:16:15.037: E/AndroidRuntime(6173): at android.os.Looper.loop(Looper.java:130)
03-08 00:16:15.037: E/AndroidRuntime(6173): at android.app.ActivityThread.main(ActivityThread.java:3687)
03-08 00:16:15.037: E/AndroidRuntime(6173): at java.lang.reflect.Method.invokeNative(Native Method)
03-08 00:16:15.037: E/AndroidRuntime(6173): at java.lang.reflect.Method.invoke(Method.java:507)
03-08 00:16:15.037: E/AndroidRuntime(6173): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
03-08 00:16:15.037: E/AndroidRuntime(6173): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
03-08 00:16:15.037: E/AndroidRuntime(6173): at dalvik.system.NativeStart.main(Native Method)
03-08 00:16:15.037: E/AndroidRuntime(6173): Caused by: java.lang.NullPointerException
03-08 00:16:15.037: E/AndroidRuntime(6173): at izzy.n.main1.populateCalendarSpinner(main1.java:62)
03-08 00:16:15.037: E/AndroidRuntime(6173): at izzy.n.main1.onCreate(main1.java:52)
03-08 00:16:15.037: E/AndroidRuntime(6173): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-08 00:16:15.037: E/AndroidRuntime(6173): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
03-08 00:16:15.037: E/AndroidRuntime(6173): ... 11 more
Here is the code for Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="izzy.n"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.READ_CALENDAR"></uses-permission>
<uses-permission android:name="android.permission.WRITE_CALENDAR"></uses-permission>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name="izzy.n.IzzynActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="izzy.n.notes"
android:label="@string/notes"></activity>
<activity
android:name="izzy.n.calculator"
android:label="@string/calculator"></activity>
<activity android:name="izzy.n.main1"
android:label="@string/app_name"></activity>
</application>
</manifest>
and finally here is the main1.java:
class MyCalendar {
public String name;
public String id;
public MyCalendar(String _name, String _id) {
name = _name;
id = _id;
}
@Override
public String toString() {
return name;
}
}
public class main1 extends Activity {
/*********************************************************************
* UI part*/
private Spinner m_spinner_calender;
private Button m_button_add;
private Button m_button_add2;
private Button m_button_getEvents;
private TextView m_text_event;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/*get calendar list and populate the view*/
getCalendars();
populateCalendarSpinner();
populateAddBtn();
populateAddBtn2();
populateTextEvent();
populateGetEventsBtn();
}
private void populateCalendarSpinner() {
m_spinner_calender = (Spinner)this.findViewById(R.id.spinner_calendar);
ArrayAdapter l_arrayAdapter = new ArrayAdapter(this.getApplicationContext(), android.R.layout.simple_spinner_item, m_calendars);
l_arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
m_spinner_calender.setAdapter(l_arrayAdapter);
m_spinner_calender.setSelection(0);
m_spinner_calender.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> p_parent, View p_view,
int p_pos, long p_id) {
m_selectedCalendarId = m_calendars[(int)p_id].id;
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {}
});
}
private void populateAddBtn() {
m_button_add = (Button) this.findViewById(R.id.button_add);
m_button_add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addEvent();
}
});
}
private void populateAddBtn2() {
m_button_add2 = (Button) this.findViewById(R.id.button_add2);
m_button_add2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addEvent2();
}
});
}
private void populateGetEventsBtn() {
m_button_getEvents = (Button) findViewById(R.id.button_get_events);
m_button_getEvents.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getLastThreeEvents();
}
});
}
private void populateTextEvent() {
m_text_event = (TextView) findViewById(R.id.text_event);
String l_str = "title: roman10 calendar tutorial test\n" +
"description: This is a simple test for calendar api\n" +
"eventLocation: @home\n" +
"start time:" + getDateTimeStr(0) + "\n" +
"end time: " + getDateTimeStr(30) + "\n" +
"event status: confirmed\n" +
"all day: no\n" +
"has alarm: yes\n";
m_text_event.setText(l_str);
}
/****************************************************************
* Data part
*/
/*retrieve a list of available calendars*/
private MyCalendar m_calendars[];
private String m_selectedCalendarId = "0";
private void getCalendars() {
String[] l_projection = new String[]{"_id", "displayName"};
Uri l_calendars;
if (Build.VERSION.SDK_INT >= 8) {
l_calendars = Uri.parse("content://com.android.calendar/calendars");
} else {
l_calendars = Uri.parse("content://calendar/calendars");
}
Cursor l_managedCursor = this.managedQuery(l_calendars, l_projection, null, null, null); //all calendars
//Cursor l_managedCursor = this.managedQuery(l_calendars, l_projection, "selected=1", null, null); //active calendars
if (l_managedCursor.moveToFirst()) {
m_calendars = new MyCalendar[l_managedCursor.getCount()];
String l_calName;
String l_calId;
int l_cnt = 0;
int l_nameCol = l_managedCursor.getColumnIndex(l_projection[1]);
int l_idCol = l_managedCursor.getColumnIndex(l_projection[0]);
do {
l_calName = l_managedCursor.getString(l_nameCol);
l_calId = l_managedCursor.getString(l_idCol);
m_calendars[l_cnt] = new MyCalendar(l_calName, l_calId);
++l_cnt;
} while (l_managedCursor.moveToNext());
}
}
/*add an event to calendar*/
private void addEvent() {
ContentValues l_event = new ContentValues();
l_event.put("calendar_id", m_selectedCalendarId);
l_event.put("title", "roman10 calendar tutorial test");
l_event.put("description", "This is a simple test for calendar api");
l_event.put("eventLocation", "@home");
l_event.put("dtstart", System.currentTimeMillis());
l_event.put("dtend", System.currentTimeMillis() + 1800*1000);
l_event.put("allDay", 0);
//status: 0~ tentative; 1~ confirmed; 2~ canceled
l_event.put("eventStatus", 1);
//0~ default; 1~ confidential; 2~ private; 3~ public
l_event.put("visibility", 0);
//0~ opaque, no timing conflict is allowed; 1~ transparency, allow overlap of scheduling
l_event.put("transparency", 0);
//0~ false; 1~ true
l_event.put("hasAlarm", 1);
Uri l_eventUri;
if (Build.VERSION.SDK_INT >= 8) {
l_eventUri = Uri.parse("content://com.android.calendar/events");
} else {
l_eventUri = Uri.parse("content://calendar/events");
}
Uri l_uri = this.getContentResolver().insert(l_eventUri, l_event);
Log.v("++++++test", l_uri.toString());
}
/*add an event through intent, this doesn't require any permission
* just send intent to android calendar
* http://www.openintents.org/en/uris*/
private void addEvent2() {
Intent l_intent = new Intent(Intent.ACTION_EDIT);
l_intent.setType("vnd.android.cursor.item/event");
//l_intent.putExtra("calendar_id", m_selectedCalendarId); //this doesn't work
l_intent.putExtra("title", "roman10 calendar tutorial test");
l_intent.putExtra("description", "This is a simple test for calendar api");
l_intent.putExtra("eventLocation", "@home");
l_intent.putExtra("beginTime", System.currentTimeMillis());
l_intent.putExtra("endTime", System.currentTimeMillis() + 1800*1000);
l_intent.putExtra("allDay", 0);
//status: 0~ tentative; 1~ confirmed; 2~ canceled
l_intent.putExtra("eventStatus", 1);
//0~ default; 1~ confidential; 2~ private; 3~ public
l_intent.putExtra("visibility", 0);
//0~ opaque, no timing conflict is allowed; 1~ transparency, allow overlap of scheduling
l_intent.putExtra("transparency", 0);
//0~ false; 1~ true
l_intent.putExtra("hasAlarm", 1);
try {
startActivity(l_intent);
} catch (Exception e) {
Toast.makeText(this.getApplicationContext(), "Sorry, no compatible calendar is found!", Toast.LENGTH_LONG).show();
}
}
/*get a list of events
* http://jimblackler.net/blog/?p=151*/
private void getLastThreeEvents() {
Uri l_eventUri;
if (Build.VERSION.SDK_INT >= 8) {
l_eventUri = Uri.parse("content://com.android.calendar/events");
} else {
l_eventUri = Uri.parse("content://calendar/events");
}
String[] l_projection = new String[]{"title", "dtstart", "dtend"};
Cursor l_managedCursor = this.managedQuery(l_eventUri, l_projection, "calendar_id=" + m_selectedCalendarId, null, "dtstart DESC, dtend DESC");
//Cursor l_managedCursor = this.managedQuery(l_eventUri, l_projection, null, null, null);
if (l_managedCursor.moveToFirst()) {
int l_cnt = 0;
String l_title;
String l_begin;
String l_end;
StringBuilder l_displayText = new StringBuilder();
int l_colTitle = l_managedCursor.getColumnIndex(l_projection[0]);
int l_colBegin = l_managedCursor.getColumnIndex(l_projection[1]);
int l_colEnd = l_managedCursor.getColumnIndex(l_projection[1]);
do {
l_title = l_managedCursor.getString(l_colTitle);
l_begin = getDateTimeStr(l_managedCursor.getString(l_colBegin));
l_end = getDateTimeStr(l_managedCursor.getString(l_colEnd));
l_displayText.append(l_title + "\n" + l_begin + "\n" + l_end + "\n----------------\n");
++l_cnt;
} while (l_managedCursor.moveToNext() && l_cnt < 3);
m_text_event.setText(l_displayText.toString());
}
}
/************************************************
* utility part
*/
private static final String DATE_TIME_FORMAT = "yyyy MMM dd, HH:mm:ss";
public static String getDateTimeStr(int p_delay_min) {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(DATE_TIME_FORMAT);
if (p_delay_min == 0) {
return sdf.format(cal.getTime());
} else {
Date l_time = cal.getTime();
l_time.setMinutes(l_time.getMinutes() + p_delay_min);
return sdf.format(l_time);
}
}
public static String getDateTimeStr(String p_time_in_millis) {
SimpleDateFormat sdf = new SimpleDateFormat(DATE_TIME_FORMAT);
Date l_time = new Date(Long.parseLong(p_time_in_millis));
return sdf.format(l_time);
}
}
A Object in the populateCalendarSpinner()
method is null . Please put try catch and debug.
Your log show
03-08 00:16:15.037: E/AndroidRuntime(6173): Caused by: java.lang.NullPointerException03-08 00:16:15.037: E/AndroidRuntime(6173): at izzy.n.main1.populateCalendarSpinner(main1.java:62)03-08 00:16:15.037: E/AndroidRuntime(6173): at izzy.n.main1.onCreate(main1.java:52)
Activity not found is the old log. You already fixed it.
这篇关于应用程序是强制关闭,当我跑了吗?无法启动活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!