这可能是因为在Android设备上没有正确地配置SQLite支持库。以下是可能解决问题的步骤:
implementation "androidx.room:room-runtime:2.3.0"
annotationProcessor "androidx.room:room-compiler:2.3.0"
@Entity
public class User {
@PrimaryKey
public int id;
public String name;
public int age;
}
@Dao
public interface UserDao {
@Query("SELECT * FROM user")
List getAll();
@Insert
void insertAll(User... users);
}
@Database(entities = {User.class}, version = 1)
public abstract class AppDatabase extends RoomDatabase {
public abstract UserDao userDao();
}
AppDatabase db = Room.databaseBuilder(getApplicationContext(),
AppDatabase.class, "database-name").build();
List users = db.userDao().getAll();
User newUser = new User();
newUser.id = 1;
newUser.name = "John";
newUser.age = 30;
db.userDao().insertAll(newUser);
如果这些步骤无法解决问题,你可以尝试重新安装应用程序,或在Android设备上使用其他SQLite库。