error: incompatible types: Object cannot be converted to MyClass

Mojtaba

I want to use @Parcel annotation instead of implementing Parcelable.
So my class is :

@Parcel
public class UserSkillSpec {
    private final String TAG = getClass().getSimpleName();

    private Skill skill;
    private int endorses = 0;
    private boolean endorsed = false;
    private List<User> endorsers = new LinkedList<>();
    private int proficiency = 0;
    private boolean verified = false;

    @ParcelConstructor
    public UserSkillSpec(Skill skill, int proficiency) {
        this.skill = skill;
        this.proficiency = proficiency;
    }

}    

when I want to build project, this error will appears in MessageBox

Error:(62, 109) error: incompatible types: Object cannot be converted to User    

and User source code is :

@Parcel
@RealmClass
public class User extends RealmObject {
    @PrimaryKey
    private String id;

    private String firstName;
    private String lastName;
    private String name;
   //and something else

    public User() {
    }
}    

Apparently this issue related to List.
How can I fix my problem?
Thanks.

EDIT1: I changed User class as below code:

@Parcel(implementations = {UserRealmProxy.class},
        value = Parcel.Serialization.BEAN,
        analyze = {User.class})
@RealmClass
public class User implements RealmModel {
    @PrimaryKey
    private String id;

    private String firstName;
    private String lastName;
    private String name;
    //somethings else

    public User() {
    }
}

in automatically generated class UserSkillSpec$$Parcelable by Parceler library,the error happened in for section :

public static void write(UserSkillSpec userSkillSpec$$1, android.os.Parcel parcel$$1, int flags$$0, IdentityCollection identityMap$$0) {
        int identity$$0 = identityMap$$0 .getKey(userSkillSpec$$1);
        if (identity$$0 != -1) {
            parcel$$1 .writeInt(identity$$0);
        } else {
            parcel$$1 .writeInt(identityMap$$0 .put(userSkillSpec$$1));
            Skill$$Parcelable.write(InjectionUtil.getField(Skill.class, UserSkillSpec.class, userSkillSpec$$1, "skill"), parcel$$1, flags$$0, identityMap$$0);
            parcel$$1 .writeInt(InjectionUtil.getField(int.class, UserSkillSpec.class, userSkillSpec$$1, "proficiency"));
            if (InjectionUtil.getField(List.class, UserSkillSpec.class, userSkillSpec$$1, "endorsers") == null) {
                parcel$$1 .writeInt(-1);
            } else {
                parcel$$1 .writeInt(InjectionUtil.getField(List.class, UserSkillSpec.class, userSkillSpec$$1, "endorsers").size());
                for (User user$$0 : InjectionUtil.getField(List.class, UserSkillSpec.class, userSkillSpec$$1, "endorsers")) {
                    User$$Parcelable.write(user$$0, parcel$$1, flags$$0, identityMap$$0);
                }
            }
            parcel$$1 .writeInt((InjectionUtil.getField(boolean.class, UserSkillSpec.class, userSkillSpec$$1, "verified")? 1 : 0));
            parcel$$1 .writeInt(InjectionUtil.getField(int.class, UserSkillSpec.class, userSkillSpec$$1, "endorses"));
            parcel$$1 .writeString(InjectionUtil.getField(String.class, UserSkillSpec.class, userSkillSpec$$1, "TAG"));
            parcel$$1 .writeInt((InjectionUtil.getField(boolean.class, UserSkillSpec.class, userSkillSpec$$1, "endorsed")? 1 : 0));
        }
    }
Mojtaba

Finally I could solve my problem,and decide to share it.
Tips: 1. List must be as Generic.List<Item> not List
2. use @ParcelPropertyConverter(ItemListParcelConverter.class) in declaration of List<Item>

so my code is like below now:

@Parcel(implementations = {UserRealmProxy.class},
        value = Parcel.Serialization.BEAN,
        analyze = {User.class})
public class User extends RealmObject {
    @PrimaryKey
    private String id;

    private String firstName;
    private String lastName;
    private String name;}    

and this one:

@Parcel
public class UserSkillSpec {
    private Skill skill;
    private int endorses = 0;
    private boolean endorsed = false;
    @ParcelPropertyConverter(ItemListParcelConverter.class)
    private List<User> endorsers = new LinkedList<>();
    private int proficiency = 0;
    private boolean verified = false;

    public UserSkillSpec() {
    }
}

and this is parcelConvertor class:

public class ItemListParcelConverter<T> extends ArrayListParcelConverter<T> {
    @Override
    public void itemToParcel(T item, Parcel parcel) {
        parcel.writeParcelable(Parcels.wrap(item), 0);
    }

    @Override
    public T itemFromParcel(Parcel parcel) {
        return Parcels.unwrap(parcel.readParcelable(getClass().getClassLoader()));
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Error: incompatible types: Object cannot be converted to char

From Dev

Error: incompatible types: Object cannot be converted to char

From Dev

Error:(28, 58) error: incompatible types: Object cannot be converted to Address

From Dev

Incompatible types: Object cannot be converted to ParseObject

From Dev

incompatible types: Object cannot be converted to CoreLabel

From Dev

Error: incompatible types: double cannot be converted to JTextField

From Dev

error: incompatible types: MainFragment cannot be converted to Activity

From Dev

error: incompatible types: int[][] cannot be converted to int

From Dev

Error:(124, 62) error: incompatible types: Class cannot be converted to Context

From Dev

Java: toString error "error: incompatible types: int cannot be converted to String"

From Dev

Why am I getting, "incompatible types: Object cannot be converted to String" with this?

From Dev

JAVA incompatible types: Object cannot be converted to my type

From Dev

incompatible types object cannot be converted to t where t is a type variable

From Java

error: incompatible types: <anonymous Callback<List<UserDataResponse>>> cannot be converted to OnNoteListener

From Dev

app setBackground() error: incompatible types: int cannot be converted to Drawable

From Dev

JAVAFX error incompatible types: FXMLLoader cannot be converted to node

From Dev

error: incompatible types: NewsLoader cannot be converted to Loader<List<News>>

From Dev

How to fix the error: incompatible types: MenuFragment cannot be converted to Fragment in android?

From Dev

Android Studio: error: incompatible types: MainActivity cannot be converted to Application

From Dev

incompatible types: Node cannot be converted to Tab

From Java

incompatible types: int cannot be converted to T

From Java

Java incompatible types: int cannot be converted to int[]

From Dev

incompatible types: HomeFragment cannot be converted to Fragment in Android

From Java

Java : incompatible types; int cannot be converted to string

From Dev

Incompatible types: Fragment cannot be converted to NavigationDrawerFragment

From Dev

incompatible types: void cannot be converted to int

From Dev

incompatible types: BigInteger cannot be converted to int

From Dev

Java incompatible types: int cannot be converted to int[]

From Dev

incompatible types: char[] cannot be converted to CharSequence

Related Related

  1. 1

    Error: incompatible types: Object cannot be converted to char

  2. 2

    Error: incompatible types: Object cannot be converted to char

  3. 3

    Error:(28, 58) error: incompatible types: Object cannot be converted to Address

  4. 4

    Incompatible types: Object cannot be converted to ParseObject

  5. 5

    incompatible types: Object cannot be converted to CoreLabel

  6. 6

    Error: incompatible types: double cannot be converted to JTextField

  7. 7

    error: incompatible types: MainFragment cannot be converted to Activity

  8. 8

    error: incompatible types: int[][] cannot be converted to int

  9. 9

    Error:(124, 62) error: incompatible types: Class cannot be converted to Context

  10. 10

    Java: toString error "error: incompatible types: int cannot be converted to String"

  11. 11

    Why am I getting, "incompatible types: Object cannot be converted to String" with this?

  12. 12

    JAVA incompatible types: Object cannot be converted to my type

  13. 13

    incompatible types object cannot be converted to t where t is a type variable

  14. 14

    error: incompatible types: <anonymous Callback<List<UserDataResponse>>> cannot be converted to OnNoteListener

  15. 15

    app setBackground() error: incompatible types: int cannot be converted to Drawable

  16. 16

    JAVAFX error incompatible types: FXMLLoader cannot be converted to node

  17. 17

    error: incompatible types: NewsLoader cannot be converted to Loader<List<News>>

  18. 18

    How to fix the error: incompatible types: MenuFragment cannot be converted to Fragment in android?

  19. 19

    Android Studio: error: incompatible types: MainActivity cannot be converted to Application

  20. 20

    incompatible types: Node cannot be converted to Tab

  21. 21

    incompatible types: int cannot be converted to T

  22. 22

    Java incompatible types: int cannot be converted to int[]

  23. 23

    incompatible types: HomeFragment cannot be converted to Fragment in Android

  24. 24

    Java : incompatible types; int cannot be converted to string

  25. 25

    Incompatible types: Fragment cannot be converted to NavigationDrawerFragment

  26. 26

    incompatible types: void cannot be converted to int

  27. 27

    incompatible types: BigInteger cannot be converted to int

  28. 28

    Java incompatible types: int cannot be converted to int[]

  29. 29

    incompatible types: char[] cannot be converted to CharSequence

HotTag

Archive