首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用Parceler打包级联类?

如何用Parceler打包级联类?
EN

Stack Overflow用户
提问于 2016-04-28 17:01:48
回答 1查看 50关注 0票数 0

我可以使用Parceler打包一些模型,如下所示:

代码语言:javascript
复制
@Parcel(Serialization.BEAN)
public class PasswordSetModel {

    private String mPassword;
    private String mRepetition;

    /* Getter & Setter */
    ...

但是,如果这个类是另一个类的一部分,则该机制不起作用。我正在为mPasswordSetModel获得一个NPE。在构造函数中创建实例不起作用,因为成员mPassword和mRepetition在解包后为空。

代码语言:javascript
复制
@Parcel
public class RegistrationModel {

    private PasswordSetModel mPasswordSetModel;

    /* Getter & Setter */
    ...

那么我如何使用Parceler来包裹它呢?

EN

回答 1

Stack Overflow用户

发布于 2016-04-28 17:38:29

好吧,问题是我使用了“错误的”setter方法。为了使用流畅的界面风格,我这样做:

代码语言:javascript
复制
public String getPassword() {
    return mPassword;
}

public PasswordSetModel setPassword(String password) {
    mPassword = password;
    return this;
}

public String getRepetition() {
    return mRepetition;
}

public PasswordSetModel setRepetition(String repetition) {
    mRepetition = repetition;
    return this;
}

现在似乎找到了setter,因此模型为空

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36909944

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档