当我开始一个新的活动时,我使用这个代码来发送参数:
Intent inputForm = new Intent(getActivity(), InputForm.class);
Bundle b = new Bundle();
b.putInt("item", Integer.parseInt(mItem.id)); //Your id
inputForm.putExtras(b); //Put your id to your next Intent
startActivity(inputForm);
我使用这段代码来读取 inputForm Activity 中的参数:
Bundle b = getIntent().getExtras();
if (b != null) {
int value = b.getInt("item");
ID = value;
}
Toast.makeText(getApplication(), "MIJN ID:" + Integer.toString(ID), Toast.LENGTH_LONG).show();
当我在我的三星 Tab 10.1 GT-P7510 ID(和我的三星 Tab 2 10.1 3G GT-P5100)上运行此代码时,始终为 0,当我在带有 JB 的 Galaxy S3 上运行相同的代码时,代码运行良好。当我使用此代码时,我收到此错误:
Intent inputForm = new Intent(getActivity(), InputForm.class);
inputForm.putExtra("item", mItem.id);
startActivityForResult(inputForm, 0);
//Read Settings in new Activity
String message;
message = getIntent().getExtras().getString("item"); //<---Nullpointerexception
Toast.makeText(getApplication(), message,Toast.LENGTH_LONG).show();
E/AndroidRuntime(2274):java.lang.RuntimeException:无法启动活动 ComponentInfo{com.obat.tabtasks/com.obat.tabtasks.InputForm}:java.lang.NullPointerException
提前致谢,
OBAT