0

I have the following entity class -

@Entity(tableName = Constants.chatsTableName)
data class ChatModelItem(
    @SerializedName("created")
    val created: String,
    @SerializedName("groupId")
    @PrimaryKey
    val groupId: String,
    @SerializedName("groupType")
    @Embedded val groupType: GroupType,
    @SerializedName("joinedAt")
    val joinedAt: String,
    @SerializedName("name")
    val name: String,
    @SerializedName("unreadMessages")
    @Embedded val unreadMessages: List<MessageLogicModel>,
    @SerializedName("userGroupRole")
    @Embedded val userGroupRole: GroupRole,
    @SerializedName("userId")
    val userId: String
) {

    data class MessageLogicModel(val id: String, val groupId: String, val senderUsername: String, val content: String,
                                 val messageType: MessageType, val created: Date)

    enum class GroupType(val value: Int) {

        Single(0), Multiple(1), BusinessChannel(2)
    }

    enum class GroupRole(val value: Int) {
        Reader(0), Writer(1), Editor(2), Admin(3)
    }

    enum class MessageType(val value: Int) {
        Text(0),
        Media(1),
        Link(2),
        Location(3),
    }
}

When starting to start my project I get the really annoying, uninformative error -

/Users/alonshlider/Developer/Android/TwoVerte/app/build/tmp/kapt3/stubs/debug/com/example/twoverte/chats/model/ChatModelItem.java:274: error: Entities and POJOs must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type).
    public static enum GroupType {
                  ^/Users/alonshlider/Developer/Android/TwoVerte/app/build/tmp/kapt3/stubs/debug/com/example/twoverte/chats/model/ChatModelItem.java:278: error: Cannot find setter for field.
        private final int value = 0;
                          ^error: Entities and POJOs must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type). - java.util.List/Users/alonshlider/Developer/Android/TwoVerte/app/build/tmp/kapt3/stubs/debug/com/example/twoverte/chats/model/ChatModelItem.java:289: error: Entities and POJOs must have a usable public constructor. You can have an empty constructor or a constructor whose parameters match the fields (by name and type).
    public static enum GroupRole {
                  ^/Users/alonshlider/Developer/Android/TwoVerte/app/build/tmp/kapt3/stubs/debug/com/example/twoverte/chats/model/ChatModelItem.java:294: error: Cannot find setter for field.
        private final int value = 0;
                          ^/Users/alonshlider/Developer/Android/TwoVerte/app/build/tmp/kapt3/stubs/debug/com/example/twoverte/chats/model/ChatModelItem.java:7: error: Multiple fields have the same columnName: value. Field names: groupType > value, userGroupRole > value.
public final class ChatModelItem {
             ^/Users/alonshlider/Developer/Android/TwoVerte/app/build/tmp/kapt3/stubs/debug/com/example/twoverte/chats/database/ChatsDao.java:19: error: There is a problem with the query: [SQLITE_ERROR] SQL error or missing database (no such table: chats_table)
    public abstract androidx.lifecycle.LiveData<java.util.List<com.example.twoverte.chats.model.ChatModelItem>> getAllChats();
[WARN] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: androidx.room.RoomProcessor (DYNAMIC).
                                                                                                                ^

I have tried the following -

1) add default value to all files

2) add secondary constructor

nothing helps and this really fustrates me.

I was able to create an entity which held an object of type List and a primary key as Int, but that is not how I want to construct my DB. So, what is it that is missing?

Alon Shlider
  • 1,187
  • 1
  • 16
  • 46
  • https://stackoverflow.com/questions/44485631/room-persistence-errorentities-and-pojos-must-have-a-usable-public-constructor – IntelliJ Amiya Apr 15 '20 at 06:23
  • 1
    @IntelliJAmiya as I have already mentioned, I have tried solutions that were provided at that topic. Hopefully you could assist me here and not link to other questions as I have already tried that solutions – Alon Shlider Apr 15 '20 at 06:43

0 Answers0