我不明白为什么我在创建这样的pendingIntent实例时会出现NullPointerException:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
if(requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
Alarm alarm = (Alarm) intent.getSerializableExtra(AlarmAdapter.ALARM_INSTANCE);
int position = intent.getIntExtra(AlarmAdapter.ITEM_POSITION_ADAPTER, 0);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), position, intentListAlarmActivityToWakeUpActivity, 0);
//setAlarm(alarm.getHourOfAlarm(), alarm.getMinutesOfAlarm(), position);
mListOfAlarm.get(position).setData(alarm);
mAlarmAdapter.notifyDataSetChanged();
}
}
PendingIntent.getActivity(...)返回null ... 以下是Android Studio中的堆栈跟踪:
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1986, result=-1, data=Intent { (has extras) }} to activity {com.selfieproduction.yacire.selfwakeup/com.selfieproduction.yacire.selfwakeup.ListAlarmActivity}: java.lang.NullPointerException
at android.app.ActivityThread.deliverResults(ActivityThread.java:3432)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3475)
at android.app.ActivityThread.access$1300(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1258)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at android.app.PendingIntent.getActivity(PendingIntent.java:261)
at android.app.PendingIntent.getActivity(PendingIntent.java:224)
at com.selfieproduction.yacire.selfwakeup.ListAlarmActivity.onActivityResult(ListAlarmActivity.java:221)
at android.app.Activity.dispatchActivityResult(Activity.java:5446)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3428)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3475)
at android.app.ActivityThread.access$1300(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1258)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
答案 0 :(得分:0)
对不起,
我的意图是假的...... 感谢Rey Pham的评论。