片段代码MoneyTransferFragment ......
MoneyTransferFragment moneyTransferFragment = new MoneyTransferFragment();
Bundle b = new Bundle();
b.putSerializable("UserValidateObject",userValidate);
b.putSerializable("BeneficiaryObject",beneficiaryDetails);
moneyTransferFragment.setArguments(b);
第二个片段的代码,我想要检索该对象.......
Bundle b = getArguments();
userValidate =(UserValidate) b.getSerializable("UserValidateObject");
Log.i("getuserValidate",userValidate.toString());
在日志中显示错误..........
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
答案 0 :(得分:4)
更改您的代码 发件人:强>
Bundle b = getArguments();
userValidate =(UserValidate) b.getSerializable("UserValidateObject");
Log.i("getuserValidate",userValidate.toString());
要强>
userValidate=(UserValidate)getArguments().getSerializable("UserValidateObject");
Log.i("getuserValidate",userValidate.toString());
活动有效:
(YourObject)getIntent().getSerializableExtra("keyname");
片段作品:
(YourObject)getArguments().getSerializable("keyname");