我为我的最后一年项目创建触发器和动作应用程序,
我将子活动结果返回到中间活动,然后向该活动添加一些数据并将其再次发送到主要活动,
我为Trigger子模块和Action子模块做了两件事,两者都是相同的编码......
触发模块工作正常,但当动作模块运行应用程序时强行停止
,错误是
E/AndroidRuntime(5104): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { (has extras) }} to activity {mani.droid.mechanize/mani.droid.mechanize.ActionListActivity}: java.lang.NullPointerException
儿童onActivityResult
public void onSave(View v)
{
if(txtNum.length() != 0)
{
String strTmp = null;
Intent resultInt = new Intent();
strTmp = txtNum.getText().toString();
resultInt.putExtra("Num", strTmp);
resultInt.putExtra("SubName", strTmp);
setResult(Activity.RESULT_OK, resultInt);
finish();
}
else
Toast.makeText(getApplicationContext(), "Please enter number or choose from contact", Toast.LENGTH_SHORT).show();
}
中级onActivityResult
//getting result from other activity and sending to action list activity
@Override
public void onActivityResult(int reqCode, int resultCode, Intent data) {
super.onActivityResult(reqCode, resultCode, data);
if(resultCode == Activity.RESULT_OK)
{
switch(reqCode)
{
case 1:
data.putExtra("ActionName", txtAction);
setResult(Activity.RESULT_OK, data);
finish();
break;
}
}
}
主要onActivityResult
//Getting Trigger parameters and adding to list
@Override
public void onActivityResult(int reqCode, int resultCode, Intent data) {
super.onActivityResult(reqCode, resultCode, data);
if(resultCode == Activity.RESULT_OK)
{
switch(reqCode)
{
case 1:
if (data.equals(null))
{
Toast.makeText(context, "Intent is Null", Toast.LENGTH_SHORT).show();
}
else
{
//String actName = data.getStringExtra("ActionName");
String subName = data.getStringExtra("SubName");
Toast.makeText(context, subName, Toast.LENGTH_SHORT).show();
}
break;
}
}
}
答案 0 :(得分:7)
这意味着Intent
接收方在其onActivityResult()
中引发了异常。我可以在此处看到NullPointerException
:data.equals(null)
肯定是错误的,因为它会在data
为null
时抛出异常。你的意思是data == null
。
答案 1 :(得分:0)
只需检查null != data
,数据等于null