【问题标题】:Failure delivering result ResultInfo(who=null, request=1, result=0, data=null)传递结果 ResultInfo(who=null, request=1, result=0, data=null) 失败
【发布时间】:2019-05-11 21:48:38
【问题描述】:

我正在尝试将结果显示为 toast,但应用程序在此行崩溃 Plant plant = (Plant) data.getSerializableExtra(PlantResultActivity.PLANT_RESULT);

PlantResultActivity:

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);

    // get the item that the user clicked
    Plant plant = (Plant) getListAdapter().getItem(position);

    // EveryThing went fine
    getIntent().putExtra(PLANT_RESULT, plant);

    // Finish this Intent
    finish();
}

高级搜索活动:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    //are we getting data returend from the plantResultIntent? If so, this if test will evaluate to true, because
    //we passed the PLANT_RESULTS constant in when invoked that intent
    if(requestCode == PLANT_RESULTS){
        //fetch the selected data using the constant that we have using as a key
        Plant plant = (Plant) data.getSerializableExtra(PlantResultActivity.PLANT_RESULT);

        //This Toast will be invoked if we recieved a result from plantResultIntent
        Toast.makeText(this, "Recieved Result " + plant, Toast.LENGTH_LONG).show();


    }
}

【问题讨论】:

  • 提供同样的 logcat
  • 我在logcat窗口中添加了错误截图!

标签: java android


【解决方案1】:

您错过了setResult 调用,并且返回的意图(您在onActivityResult 中使用的意图)为空

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);

    // get the item that the user clicked
    Plant plant = (Plant) getListAdapter().getItem(position);
    Intent intent = new Intent();
    // EveryThing went fine
    intent.putExtra(PLANT_RESULT, plant);
    setResult(RESULT_OK, intent);
    // Finish this Intent
    finish();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多