Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 传递结果ResultInfo失败(who=null,request=1,result=0,data=null)_Java_Android - Fatal编程技术网

Java 传递结果ResultInfo失败(who=null,request=1,result=0,data=null)

Java 传递结果ResultInfo失败(who=null,request=1,result=0,data=null),java,android,Java,Android,我试图将结果显示为toast,但应用程序在以下行崩溃Plant Plant=(Plant)data.getSerializableExtra(PlantResultActivity.Plant_result) 植物触觉: @Override protected void onListItemClick(ListView l, View v, int position, long id) { // TODO Auto-generated method stub super.onLi

我试图将结果显示为toast,但应用程序在以下行崩溃
Plant Plant=(Plant)data.getSerializableExtra(PlantResultActivity.Plant_result)

植物触觉:

@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();


    }
}

您错过了
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();
}

为sameI提供logcat在logcat窗口中添加了错误截图!