2015-01-21 106 views
1

我試圖讓顯示敬酒的結果,但在該行Plant plant = (Plant) data.getSerializableExtra(PlantResultActivity.PLANT_RESULT);未能提供結果ResultInfo(誰= NULL,請求= 1,結果爲0,數據= NULL)

PlantResultActivity應用程序崩潰:

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

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

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

 
\t \t // Finish this Intent 
 
\t \t finish(); 
 
\t }

AdvancedSearchActivity:

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

enter image description here

+0

爲我添加了錯誤的截圖一樣 – PPD 2015-01-21 10:34:11

+0

提供的logcat在logcat窗口中! – ocean 2015-01-21 10:36:03

回答

3

你錯過了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(); 
} 
相關問題