我正在尝试使用新的体系结构组件,但是当我尝试运行时,我得到:
“错误:(375,24)错误:查询存在问题:[SQLITE_ERROR] SQL错误或缺少数据库(无此类表:文章)”
以下是我的类(class)。
**实体 : **
@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);
}
数据库:
@Database(entities = {Post.class}, version = 1)
public static abstract class AppDatabase extends RoomDatabase {
public abstract PostDao postDao();
}
最佳答案
https://developer.android.com/topic/libraries/architecture/room.html
似乎您认为它将自己使该类多元化。
因此,要么使用SELECT * FROM Post
或做
@Entity(tableName = "posts")
class Post {
...
}