简体   繁体   中英

Dagger has conflict with parcel

As I want to send data in putExtra method I try to use parcel annotation, when I add @parcel to may data model class I catch these errors. before add @parcel on my data model class, I have no error.

error: cannot find symbol class DaggerApplicationComponent

error: Parceler: No @ParcelConstructor annotated constructor and no default empty bean constructor found.

this is my class App(class G)

    public class App extends Application {

    static ApplicationComponent component;

    @Override
    public void onCreate() {
        super.onCreate();

        component = DaggerApplicationComponent.builder()
                .androidModule(new AndroidModule(this))
                .build();
    }
    public static ApplicationComponent getComponent()
    {
        return component;
    }
}

and this is my UserData class(data model)

@Parcel
public class UserData {

    private int id;
    private String email;
    private String first_name;
    private   String last_name;
    private String avatar;

    public UserData(int id, String email, String first_name, String last_name, String avatar) {
        this.id = id;
        this.email = email;
        this.first_name = first_name;
        this.last_name = last_name;
        this.avatar = avatar;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getFirst_name() {
        return first_name;
    }

    public void setFirst_name(String first_name) {
        this.first_name = first_name;
    }

    public String getLast_name() {
        return last_name;
    }

    public void setLast_name(String last_name) {
        this.last_name = last_name;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }
}

It seems, that the parceler requires the annotated class to have a constructor without params or one that is annotated with @ParcelConstructor. I don't think it has anything to do with dagger.

Dagger is not the problem. You got the

error: cannot find symbol class DaggerApplicationComponent

because the annotation processor failed. Therefore, Dagger couldn't generate your DaggerApplicationComponent . The real issue, as stated in your logs, is your data class. You need to annotate your constructor with @ParcelConstructor :

@Parcel
public class UserData {

    private int id;
    private String email;
    private String first_name;
    private   String last_name;
    private String avatar;

    @ParcelConstructor
    public UserData(int id, String email, String first_name, String last_name, String avatar) {
        this.id = id;
        this.email = email;
        this.first_name = first_name;
        this.last_name = last_name;
        this.avatar = avatar;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getFirst_name() {
        return first_name;
    }

    public void setFirst_name(String first_name) {
        this.first_name = first_name;
    }

    public String getLast_name() {
        return last_name;
    }

    public void setLast_name(String last_name) {
        this.last_name = last_name;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM