Search code examples
androidparcelableparcelparceler

Android: Parcel class wrapping error


I created class File with to classes and primitive types.

When i try to wrap it, have an error:

Unable to find generated Parcelable class, verify that your class is configured properly and that the Parcelable class is generated by 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;
    }
}

What wrong in my code?

Big thanks for help.


Solution

  • This is the error thrown if no Parcelable classes are generated. This is most likely due to a build misconfiguration. Verify your build and make sure you have the Parceler dependencies declared as follows:

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

    http://parceler.org/#getting_parceler