[英]Intent.getInt() doesn't work on ICS, but works on JB
I use this code to send parameters when I start a new Activity: 启动新的Activity时,我使用以下代码发送参数:
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);
And I use this code for reading the parameters in the inputForm Activity: 我使用以下代码读取inputForm活动中的参数:
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();
When I run this code on my Samsung Tab 10.1 GT-P7510 ID (and my Samsung Tab 2 10.1 3G GT-P5100) is alsways 0, when I run the same code on my Galaxy S3 with JB the code just works fine. 当我在Samsung Tab 10.1 GT-P7510 ID(和Samsung Tab 2 10.1 3G GT-P5100)上运行此代码时,始终为0,当我在带有JB的Galaxy S3上运行相同的代码时,该代码运行良好。 When I use this code I get this error: 当我使用此代码时,出现以下错误:
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: Unable to start activity ComponentInfo{com.obat.tabtasks/com.obat.tabtasks.InputForm}: java.lang.NullPointerException E / AndroidRuntime(2274):java.lang.RuntimeException:无法启动活动ComponentInfo {com.obat.tabtasks / com.obat.tabtasks.InputForm}:java.lang.NullPointerException
Thanks in advance, 提前致谢,
ObAt 观察者
try: 尝试:
Intent inputForm = new Intent(getActivity(), InputForm.class);
inputFrom.putExtra("item",Integer.parseInt(mItem.id));
startActivity(inputForm);
Could you split the line in 你能把线分开吗
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
String message = bundle.getString("passed");
and check again where the NPE is? 并再次检查NPE在哪里?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.