Database not implemented

I am testing a new Room ORM from Google Android Architecture components, I followed the documentation, but when I run my code I get java.lang.RuntimeException: cannot find implementation for com.zeyad.usecases.app.UserDatabase. 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' }
}
}

      

Gradle 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;
    }
}

      

UserDatabase:

@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);
}

      

OnCreate app:

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

      

Thanks in advance.

+3


source to share


2 answers


In my case, I was using an older version of ButterKnife which required a plugin android-apt

. So I updated ButterKnife (which now uses the annotation processor) and removed the plugin declaration in the Gradle file .



It probably wasn't really your problem, but maybe it will help others.

+5


source


Another issue that can cause the problem:



configurations.all {
  resolutionStrategy {
    force "com.android.support:support-annotations:$SUPPORT_LIBRARY_VERSION"
  }
}

      

0


source







All Articles