Java – Room database not implemented

Room database not implemented… here is a solution to the problem.

Room database not implemented

I

was trying the new Room ORM from googles Android Architecture Components and I followed the documentation, but when I ran my code, I got the java.lang.RuntimeException: cannot find implementation for com.zeyad.usecases.app。 User database. UserDatabase_Impl does not exist

Here is my code :

Gradle Project:

allprojects {
repositories {
    jcenter()
    maven { url 'https://jitpack.io' }
    maven { url 'https://maven.google.com' }
}
}

Gradient module:

compile "android.arch.lifecycle:runtime:1.0.0-alpha1"
compile "android.arch.lifecycle:extensions:1.0.0-alpha1"
annotationProcessor "android.arch.lifecycle:compiler:1.0.0-alpha1"
compile "android.arch.persistence.room:runtime:1.0.0-alpha1"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha1"

User:

@Entity(tableName = "User")
public class User {

static final String LOGIN = "login";
    private static final String ID = "id", AVATAR_URL = "avatar_url";
    @PrimaryKey
    @SerializedName(LOGIN)
    @ColumnInfo(name = LOGIN)
    String login;

@SerializedName(ID)
    @ColumnInfo(name = ID)
    int id;

@SerializedName(AVATAR_URL)
    @ColumnInfo(name = AVATAR_URL)
    String avatarUrl;

public User() {
    }

public User(String login, int id, String avatarUrl) {
        this.login = login;
        this.id = id;
        this.avatarUrl = avatarUrl;
    }

public static boolean isEmpty(User user) {
        return user == null || (user.login == null && user.avatarUrl == null);
    }

public String getLogin() {
        return login;
    }

public void setLogin(String login) {
        this.login = login;
    }

public int getId() {
        return id;
    }

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

public String getAvatarUrl() {
        return avatarUrl;
    }

public void setAvatarUrl(String avatarUrl) {
        this.avatarUrl = avatarUrl;
    }

@Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

User user = (User) o;

return id == user.id && (login != null ? login.equals(user.login) : user.login == null
                && (avatarUrl != null ? avatarUrl.equals(user.avatarUrl) : user.avatarUrl == null));
    }

@Override
    public int hashCode() {
        int result = login != null ? login.hashCode() : 0;
        result = 31 * result + id;
        result = 31 * result + (avatarUrl != null ? avatarUrl.hashCode() : 0);
        return result;
    }
}

User database:

@Database(entities = {User.class}, version = 1)
public abstract class UserDatabase extends RoomDatabase {
    public abstract RoomBaseDao roomBaseDao();
}

RoomBaseDao:

@Dao
public interface RoomBaseDao {

@Insert(onConflict = OnConflictStrategy.REPLACE)
    void insertItemsReplace(User... objects);

@Update(onConflict = OnConflictStrategy.REPLACE)
    void updateItemsReplace(User... objects);

@Delete
    void deleteItem(User object);
}

App at creation time:

UserDatabase gDb = Room.databaseBuilder(this, UserDatabase.class, "test-db").build();  throws the exception above

Thanks in advance.

Solution

In my case, I’m using an older version of ButterKnife, which requires the android-apt plugin. So I updated ButterKnife (now using the comment processor) and removed the plugin declaration in the Gradle file.

Maybe it’s not exactly your problem, but maybe it will help others.

Related Problems and Solutions