Android:无法传送结果ResultInfo [英] Android: Failure delivering result ResultInfo
问题描述
我在TabHost
中有一个活动A,先是A startActivityForResult(B)
,然后是B startActivityForResult(C)
.
我遇到的问题是:
在C中,当我setResult(RESULT_OK,intent)时,发生
I have an Activity A in TabHost
, A startActivityForResult(B)
then B startActivityForResult(C)
.
The problem I meet is that:
In C when I setResult(RESULT_OK, intent), occur
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=Intent { (has extras) }} to activity {com.hackingtrace.vancexu/com.hackingtrace.vancexu.task.B}: java.lang.NullPointerException
在B中,我以
setTimeButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent i = new Intent(view.getContext(), TaskTimeSet.class);
i.putExtra(TasksDbAdapter.KEY_ROWID, mRowId);
Calendar c = Calendar.getInstance();
Date d = c.getTime();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String now = sdf.format(d);
i.putExtra("date", now);
startActivityForResult(i, ACTIVITY_EDIT_TIME);
}
在C语言中,我通过
confirmBtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.putExtra("date", resultDate);
int h = timePicker.getCurrentHour();
int m = timePicker.getCurrentMinute();
String time = "" +h+":"+m;
Log.d(TAG, time);
intent.putExtra("time", time);
setResult(RESULT_OK, intent);
finish();
}
});
然后在B中,我收到
protected void onActivityResult(int requestCode, int resultCode,
Intent intent) {
Log.d(TAG, "I am in " + requestCode + resultCode);
super.onActivityResult(requestCode, resultCode, intent);
if (requestCode == ACTIVITY_EDIT_TIME) {
if (resultCode == RESULT_OK) {
Log.d(TAG, "OK time set");
String[] dateArr = intent.getStringExtra("date").split("-");
String[] timeArr = intent.getStringExtra("time").split(":");
int year = Integer.parseInt(dateArr[0]);
int month = Integer.parseInt(dateArr[1]);
int day = Integer.parseInt(dateArr[2]);
int hour = Integer.parseInt(timeArr[0]);
int minute = Integer.parseInt(timeArr[1]);
Log.d(TAG, ""+year+month+day+hour+minute);
}
}
}
但是我从来没有得到"Log.d(TAG," + year + month + day + hour + minute);正常运行.
But I never get the "Log.d(TAG, ""+year+month+day+hour+minute);" run normally.
我尝试过:
1:
I have tried:
1:
if (getParent() == null) {
setResult(Activity.RESULT_OK, intent);
}
else {
getParent().setResult(Activity.RESULT_OK, intent);
}
不起作用:(
2:
not work :(
2:
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
不会发生错误"java.lang.RuntimeException",但requestCode和resultCode始终为0.
the error "java.lang.RuntimeException" not occur, but the requestCode and resultCode is 0 always.
推荐答案
在C中,我放置了ExtExtra 2字符串(resultDate和time),但是我错过了将resultDate放入意图时可能未初始化的问题.所以我得到了错误:java.lang.NullPointerException
.
In C I putExtra 2 string (resultDate and time), but I miss the point that resultDate may not be initialized when it is be put into intent. So I got the Error: java.lang.NullPointerException
.
这篇关于Android:无法传送结果ResultInfo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!