Java Intent.getInt()不';不适用于IC,但适用于JB
我使用此代码在启动新活动时发送参数:Java Intent.getInt()不';不适用于IC,但适用于JB,java,android,android-intent,nullpointerexception,Java,Android,Android Intent,Nullpointerexception,我使用此代码在启动新活动时发送参数: 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);
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);
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();
我使用此代码读取inputForm活动中的参数:
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);
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,当我在我的Galaxy S3和JB上运行相同的代码时,代码工作正常。当我使用此代码时,会出现以下错误:
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();
Intent inputForm=newintent(getActivity(),inputForm.class);
inputForm.putExtra(“项目”,斜接id);
startActivityForResult(inputForm,0);
//阅读新活动中的设置
字符串消息;
message=getIntent().getExtras().getString(“项”)// 尝试:
你能把电话分线吗
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
String message = bundle.getString("passed");
然后再次检查NPE的位置?您确定Samsung Tab 10.1 GT-P7510上的mItem.id不是零吗?是的,我从主/详细流程开始新活动。我有3个片段,每个片段上的mItem.id是不同的。当我启动第二个片段时,mItem.id必须是1,当我启动第三个片段时,mItem.id必须是2。mItem.id是字符串吗?你能在将其放入捆绑包之前打印出它的值吗?在inputForm中,活动b不是空的?我测试了它,b是空的,我不知道为什么,因为在我的SGS3上,b不是空的。安卓版本的平板电脑是什么?你从哪里创建意图?(getActivity()调用表明它不在另一个activity中)4.0.4这是我的activity公共类TaskDetailFragment扩展了Fragments我也尝试了Galaxy Tab 2 10.1 3G(GT-P5100)和Android 4.0.4股票看看这篇文章,也许它的问题与你(他使用Tab)的问题相同。我尝试了链接上的一切,但我无法修复它。我还尝试使用此代码,但我的类中未定义getArguments:if(getArguments().containsKey(“myItem”){ID=MyTasks.ITEM_MAP.get(getArguments().getString(ARG_ITEM_ID));}