8

我为我的最后一年项目创建触发器和操作应用程序,

我将子活动结果返回给中间活动,然后向该活动添加一些数据并将其再次发送到主要活动,

我为 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;
        }
    }
} 
4

2 回答 2

8

这意味着Intent接收方在其onActivityResult(). 我可以在NullPointerException这里看到正确的:绝对错误,因为它在isdata.equals(null)时抛出异常。你的意思是。datanulldata == null

于 2012-06-18T14:26:56.347 回答
0

只需检查null != data,因为数据等于 null

于 2015-12-03T12:42:58.413 回答