android-room
Room attempt to re-open an already closed database
It’s because you are trying to modify the schema of the existing database without giving it any migration information. So basically it attempts to write the new database schema to the existing DB which doesn’t work. There are two ways around this. If you are in your development environment what you can do is fallback … Read more
Android Persistence room: “Cannot figure out how to read this field from a cursor”
Document is really confusing. Try with just below classes: 1) User Entity: @Entity public class User { @PrimaryKey public int id; // User id } 2) Pet Entity: @Entity public class Pet { @PrimaryKey public int id; // Pet id public int userId; // User id public String name; } 3) UserWithPets POJO: // Note: … Read more
How to use parameter fields in Room @Query?
You can’t pass parameters like that to room. It does not support a full expression language. You have to use primitive types to pass parameters. Like this, @Query(“SELECT * FROM ticket where user_id = :user_id”) LiveData<Ticket> loadFromUser(String user_id);
LiveData.getValue() returns null with Room
On the next line I am checking sections.getValue() which is always giving me null although I have data in the DataBase and later I am getting the value in the onChanged() method. This is normal behavior, because queries that return LiveData, are working asynchronously. The value is null at that moment. So calling this method … Read more
coroutine Flow : Not sure how to convert a Cursor to this method’s return type
Do not use both suspend and Flow<> on the same method! Like this @Query(“SELECT * FROM user”) suspend fun loadAll(): Flow<Array<User>> Just @Query(“SELECT * FROM user”) suspend fun loadAll(): Array<User> OR @Query(“SELECT * FROM user”) fun loadAll(): Flow<Array<User>>
Android Room database file is empty – .db, .db-shm, .db-wal
Go to folder Data/data/packageName/databases/ There has to be three files .db, .db-shm, .db-wal, copy all three files to one location and then open your Myapp.db these two extra files are needed to open db file