问题描述
我得在一个类中这个方法填充数据的意图,然后将它传递回启动该法的活动。在这里,我使用的意图,该项目中的onActivityResult添加到我的数据库()
但正如标题所示,我得到一个失败的结果提供resultinfo的错误。
任何人都可以明白为什么我得到这个错误?
我的继承人code的重要组成部分:
从类1,接收目标:
@覆盖
保护无效的onActivityResult(INT REQ code,INT资源$ C $ C,意图数据){
super.onActivityResult(REQ code,水库code,数据); 如果(REQ code == ENTER_DATA_REQUEST_ code和;&安培; RES code == RESULT_OK){
hkDBhelper.addItem(data.getExtras()。的getString(tag_grocery_foodItem),
data.getExtras()。的getString(tag_grocery_weight),
data.getExtras()。的getString(tag_grocery_price),
data.getExtras()。的getString(tag_grocery_brand),
。data.getExtras()的getString(tag_grocery_category));
hkCursorA.changeCursor(hkDBhelper.listAll());
}
}
编辑:补充说:
@覆盖
公共布尔onOptionsItemSelected(菜单项项){
INT ID = item.getItemId();
如果(ID == R.id.addItem){
startActivityForResult(新意图(这一点,AddFood.class),ENTER_DATA_REQUEST_ code);
返回true;
}
返回super.onOptionsItemSelected(项目);
}
和2级,送INTNET:
公共无效的addItem(){
。setFood = itemFood.getText()的toString();
。setWeight = itemWeight.getText()的toString();
。setPrice = itemPrice.getText()的toString();
。setBrand = itemBrand.getText()的toString();
。setCategory = catagorySpinner.getSelectedItem()的toString();
如果(setFood.length()= 0&放大器;!&放大器; setWeight.length()= 0&放大器;!&放大器;!setPrice.length()= 0
&功放;&安培; setBrand.length()= 0&安培;!&安培; setCategory.length()!= 0){
意向newIntent = getIntent();
newIntent.putExtra(tag_grocery_foodItem,setFood);
newIntent.putExtra(tag_grocery_weight,setWeight);
newIntent.putExtra(tag_grocery_price,setPrice);
newIntent.putExtra(tag_grocery_brand,setBrand);
newIntent.putExtra(tag_grocery_category,setCategory); this.setResult(RESULT_OK,newIntent);
完();
}
}
和继承人一些来自logcat的行:
9月10日至29日:28:23.569:E / AndroidRuntime(32565):了java.lang.RuntimeException:失败交付结果
ResultInfo {谁= NULL,请求= 1,结果= -1,数据= {意向CMP = com.example.s188094_mappe3 / .AddFood
(有临时演员)}}到活动{com.example.s188094_mappe3 / com.example.s188094_mappe3.MainActivity}:
显示java.lang.NullPointerException
试试这个办法,希望这将帮助你解决你的问题。
有是双向的发送/从另一个activty获取数据/
1.新增数据的意图。
如何把:
意图newIntent =新意图();
newIntent.putExtra(tag_grocery_foodItem,setFood);
newIntent.putExtra(tag_grocery_weight,setWeight);
newIntent.putExtra(tag_grocery_price,setPrice);
newIntent.putExtra(tag_grocery_brand,setBrand);
newIntent.putExtra(tag_grocery_category,setCategory);
的setResult(RESULT_OK,newIntent);
完();
如何获得:
如果(REQ code == ENTER_DATA_REQUEST_ code和;&安培; RES code == RESULT_OK){
hkDBhelper.addItem(data.getStringExtra(tag_grocery_foodItem),
data.getStringExtra(tag_grocery_weight),
data.getStringExtra(tag_grocery_price),
data.getStringExtra(tag_grocery_brand),
data.getStringExtra(tag_grocery_category));
hkCursorA.changeCursor(hkDBhelper.listAll());
}
2.增加数据捆绑,并添加束意图。
如何把:
意图newIntent =新意图();
束束=新包();
bundle.putString(tag_grocery_foodItem,setFood);
bundle.putString(tag_grocery_weight,setWeight);
bundle.putString(tag_grocery_price,setPrice);
bundle.putString(tag_grocery_brand,setBrand);
bundle.putString(tag_grocery_category,setCategory);
newIntent.putExtras(包);
的setResult(RESULT_OK,newIntent);
完();
如何获得:
如果(REQ code == ENTER_DATA_REQUEST_ code和;&安培; RES code == RESULT_OK){
hkDBhelper.addItem(data.getExtras()。的getString(tag_grocery_foodItem),
data.getExtras()。的getString(tag_grocery_weight),
data.getExtras()。的getString(tag_grocery_price),
data.getExtras()。的getString(tag_grocery_brand),
。data.getExtras()的getString(tag_grocery_category));
hkCursorA.changeCursor(hkDBhelper.listAll());
}
I've got this method in one class filling an Intent with data and then pass it back to the activity that started the method. Here I am using the intent to add the item to my database in onActivityResult()
But as the title indicates I'm getting an "failure delivering result resultinfo" error.
Can anyone see why I get this error?
Heres the essential part of my code:
from class 1, receiving the Intent :
@Override
protected void onActivityResult(int reqCode, int resCode, Intent data){
super.onActivityResult(reqCode, resCode, data);
if(reqCode == ENTER_DATA_REQUEST_CODE && resCode == RESULT_OK){
hkDBhelper.addItem(data.getExtras().getString("tag_grocery_foodItem"),
data.getExtras().getString("tag_grocery_weight"),
data.getExtras().getString("tag_grocery_price"),
data.getExtras().getString("tag_grocery_brand"),
data.getExtras().getString("tag_grocery_category"));
hkCursorA.changeCursor(hkDBhelper.listAll());
}
}
Edit: added:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.addItem) {
startActivityForResult(new Intent(this, AddFood.class), ENTER_DATA_REQUEST_CODE);
return true;
}
return super.onOptionsItemSelected(item);
}
And class 2, sending the Intnet:
public void addItem(){
setFood = itemFood.getText().toString();
setWeight = itemWeight.getText().toString();
setPrice = itemPrice.getText().toString();
setBrand = itemBrand.getText().toString();
setCategory = catagorySpinner.getSelectedItem().toString();
if(setFood.length() != 0 && setWeight.length() != 0 && setPrice.length() != 0
&& setBrand.length() != 0 && setCategory.length() != 0){
Intent newIntent = getIntent();
newIntent.putExtra("tag_grocery_foodItem", setFood);
newIntent.putExtra("tag_grocery_weight", setWeight);
newIntent.putExtra("tag_grocery_price", setPrice);
newIntent.putExtra("tag_grocery_brand", setBrand);
newIntent.putExtra("tag_grocery_category", setCategory);
this.setResult(RESULT_OK, newIntent);
finish();
}
}
And heres some lines from logcat:
10-29 09:28:23.569: E/AndroidRuntime(32565): java.lang.RuntimeException: Failure delivering result
ResultInfo{who=null, request=1, result=-1, data=Intent { cmp=com.example.s188094_mappe3/.AddFood
(has extras) }} to activity {com.example.s188094_mappe3/com.example.s188094_mappe3.MainActivity}:
java.lang.NullPointerException
Try this way,hope this will help you to solve your problem.
There is two way send/get data to/from another activty
1.add data to intent.
how to put :
Intent newIntent = new Intent();
newIntent.putExtra("tag_grocery_foodItem", setFood);
newIntent.putExtra("tag_grocery_weight", setWeight);
newIntent.putExtra("tag_grocery_price", setPrice);
newIntent.putExtra("tag_grocery_brand", setBrand);
newIntent.putExtra("tag_grocery_category", setCategory);
setResult(RESULT_OK, newIntent);
finish();
how to get :
if(reqCode == ENTER_DATA_REQUEST_CODE && resCode == RESULT_OK){
hkDBhelper.addItem(data.getStringExtra("tag_grocery_foodItem"),
data.getStringExtra("tag_grocery_weight"),
data.getStringExtra("tag_grocery_price"),
data.getStringExtra("tag_grocery_brand"),
data.getStringExtra("tag_grocery_category"));
hkCursorA.changeCursor(hkDBhelper.listAll());
}
2.Add data to bundle and add bundle to intent.
how to put :
Intent newIntent = new Intent();
Bundle bundle = new Bundle();
bundle.putString("tag_grocery_foodItem", setFood);
bundle.putString("tag_grocery_weight", setWeight);
bundle.putString("tag_grocery_price", setPrice);
bundle.putString("tag_grocery_brand", setBrand);
bundle.putString("tag_grocery_category", setCategory);
newIntent.putExtras(bundle);
setResult(RESULT_OK, newIntent);
finish();
how to get :
if(reqCode == ENTER_DATA_REQUEST_CODE && resCode == RESULT_OK){
hkDBhelper.addItem(data.getExtras().getString("tag_grocery_foodItem"),
data.getExtras().getString("tag_grocery_weight"),
data.getExtras().getString("tag_grocery_price"),
data.getExtras().getString("tag_grocery_brand"),
data.getExtras().getString("tag_grocery_category"));
hkCursorA.changeCursor(hkDBhelper.listAll());
}
这篇关于的onActivityResult()和:未能交付结果resultinfo谁= NULL请求= 1的结果= -1数据=意图(有临时演员)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!