0

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;
    }
}
papafe
  • 2,959
  • 4
  • 41
  • 72

2 Answers2

1

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.

Ridcully
  • 23,362
  • 7
  • 71
  • 86
0

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;
    }
}
Benjamin
  • 7,055
  • 6
  • 40
  • 60