我正在尝试使用会议室数据库读取ID和名字,但是在运行应用程序之前出现了此错误:
未将架构导出目录提供给注释处理器,因此 我们无法导出架构。您可以提供
room.schemaLocation
注解处理器参数或设置 exportSchema为false。
如果我分别读取ID或名字,但不能同时读取ID和名,则没有问题
代码示例(这可以正常工作)
AppDatabase appDatabase;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_categories);
ButterKnife.bind(this);
appDatabase = Room.databaseBuilder(CategoriesActivity.this, AppDatabase.class, "RDatabase").allowMainThreadQueries().build();
Log.w("name", appDatabase.userDao().getAll());
}
@Entity
public class User {
@PrimaryKey
int uid;
@ColumnInfo(name = "first_name")
String firstName;
}
@Dao
public interface UserDao {
@Insert
void insertAll(User... users);
@Query("SELECT first_name FROM user")
String getAll();
}
@Database(entities = {User.class}, version = 1)
public abstract static class AppDatabase extends RoomDatabase {
public abstract UserDao userDao();
}
代码示例(由于我同时读取了id和名字,因此无法正常工作)
AppDatabase appDatabase;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_categories);
ButterKnife.bind(this);
appDatabase = Room.databaseBuilder(CategoriesActivity.this, AppDatabase.class, "RDatabase").allowMainThreadQueries().build();
List<User> a = appDatabase.userDao().getAll();
Log.w("aaa","" + a.get(0).uid);
}
@Entity
public class User {
@PrimaryKey
int uid;
@ColumnInfo(name = "first_name")
String firstName;
}
@Dao
public interface UserDao {
@Insert
void insertAll(User... users);
@Query("SELECT uid,first_name FROM user")
List<User> getAll();
}
@Database(entities = {User.class}, version = 1)
public abstract static class AppDatabase extends RoomDatabase {
public abstract UserDao userDao();
}
我尝试将exportSchema to false
放在版本之后,但出现此错误
错误:一个包含CategoriesActivity.User的封闭实例是 必填