Android: 包裹 class 包装错误

Android: Parcel class wrapping error

我创建了 class 具有 classes 和原始类型的文件。

当我尝试包装它时,出现错误:

无法找到生成的 Parcelable class,确认您的 class 配置正确并且 Parcelable class 是由 Parceler 生成的。

File.class:

@Parcel
public class File {
    int id;
    FileData data;
    FileMeta meta;
    String cypher_key;
    boolean isNew;

    public File() {
        isNew  = true;
    }

    public File(int id, FileData data, FileMeta meta, String cypher_key) {
        this.id = id;
        this.data = data;
        this.meta = meta;
        this.cypher_key = cypher_key;
        isNew = false;
    }

    public int getId() {
        return this.id;
    }

    public int getFileDataId() {
        return this.data.getId();
    }

    public int getFileDataVersion() {
        return this.data.getVersion();
    }

    public String getFileUrl() {
        return this.data.getUrl();
    }

    public String getFileType() {
        return this.data.getTagType();
    }

    public String getFileDaraInit() {
        return this.data.getInintDate();
    }

    public String getMetaDetailes() {
        return this.meta.getDetails();
    }

    public int getMetaVersion() {
        return this.meta.getVersion();
    }

    public String getMetaDateInit() {
        return this.meta.getInitDate();
    }

    public String getMetaDateModif() {
        return this.meta.getModifDate();
    }

    public boolean isNew(){
        return this.isNew;
    }


    public void setFileType(String type){
        if (data!=null){
            data.setTypeTag(type);
        }else{
            data = new FileData();
            data.setTypeTag(type);
        }
    }
}

FileMeta.class:

@Parcel
public class FileMeta {
    String details;
    int version;
    String dt_initialization;
    String dt_modification;

    public FileMeta() {

    }

    public FileMeta(String details, int version, String dt_initialization, String dt_modification) {
        this.details = details;
        this.version = version;
        this.dt_initialization = dt_initialization;
        this.dt_modification = dt_modification;
    }

    public String getDetails() {
        return this.details;
    }

    public int getVersion() {
        return this.version;
    }

    public String getInitDate() {
        return this.dt_initialization;
    }

    public String getModifDate() {
        return this.dt_modification;
    }
}

FileData.class:

@Parcel
public class FileData {
    int id;
    String url;
    int version;
    String type_tag;
    String dt_initialization;

    public FileData() {
    }

    public FileData(int id, String url, int version, String type_tag, String dt_initialization) {
        this.id = id;
        this.url = url;
        this.version = version;
        this.type_tag = type_tag;
        this.dt_initialization = dt_initialization;
    }

    public int getId() {
        return this.id;
    }

    public int getVersion() {
        return this.version;
    }

    public String getUrl() {
        return this.url;
    }

    public String getTagType() {
        return this.type_tag;
    }

    public String getInintDate(){
        return this.dt_initialization;
    }

    public void setTypeTag(String typeTag){
        this.type_tag = typeTag;
    }
}

我的代码有什么问题?

非常感谢您的帮助。

如果没有生成 Parcelable 类,这是抛出的错误。这很可能是由于构建配置错误造成的。验证您的构建并确保您具有如下声明的 Parceler 依赖项:

compile "org.parceler:parceler-api:1.0.4"
apt "org.parceler:parceler:1.0.4"

http://parceler.org/#getting_parceler