I'm trying to use the new Architecture components, but when I try to run, I get :
"Error:(375, 24) error: There is a problem with the query: [SQLITE_ERROR] SQL error or missing database (no such table: posts)"
The following are my classes.
**ENTITY : **
@Entity
public static class Post {
@PrimaryKey
private String id;
@ColumnInfo(name = "data")
private String data;
public String getId() {
return id;
}
public void setData(String data) {
this.data = data;
}
public String getData() {
return data;
}
public void setId(String id) {
this.id = id;
}
}
DAO :
@Dao
public interface PostDao {
@Query("SELECT * FROM posts")
LiveData<List<Post>> getAll();
@Insert
void insertAll(Post... posts);
@Insert
void insert(Post post);
@Delete
void delete(Post post);
}
The database :
@Database(entities = {Post.class}, version = 1)
public static abstract class AppDatabase extends RoomDatabase {
public abstract PostDao postDao();
}
By default, Room uses the class name as the database table name. If you want the table to have a different name, set the tableName property of the @Entity annotation, as shown in the following code snippet:
https://developer.android.com/topic/libraries/architecture/room.html
It seems you assumed it would pluralize the class on its own.
So, either use SELECT * FROM Post
or do
@Entity(tableName = "posts")
class Post {
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With