gpt4 book ai didi

android - 如何将对象从一个 fragment 传递到另一个 fragment ?

转载 作者:搜寻专家 更新时间:2023-11-01 07:47:06 27 4
gpt4 key购买 nike

MoneyTransferFragment fragment 代码......

MoneyTransferFragment moneyTransferFragment = new MoneyTransferFragment();
Bundle b = new Bundle();
b.putSerializable("UserValidateObject",userValidate);
b.putSerializable("BeneficiaryObject",beneficiaryDetails);
moneyTransferFragment.setArguments(b);

我想检索该对象的第二个 fragment 的代码......

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

最佳答案

更改代码来自:

Bundle b = getArguments();
userValidate =(UserValidate) b.getSerializable("UserValidateObject");
Log.i("getuserValidate",userValidate.toString());

收件人:

userValidate=(UserValidate)getArguments().getSerializable("UserValidateObject");
Log.i("getuserValidate",userValidate.toString());

Activity 作品:

    (YourObject)getIntent().getSerializableExtra("keyname");

fragment 作品:

 (YourObject)getArguments().getSerializable("keyname");

关于android - 如何将对象从一个 fragment 传递到另一个 fragment ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41741651/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com