Questions tagged [android-room]

For questions related to Android Room Persistence Library (which is a part of Android Architecture Components)

Room provides an abstraction layer over SQLite to allow fluent database access while harnessing the full power of SQLite.

6786 questions
2
votes
1 answer

AndroidX Room generated class error: "Class is public, should be declared in a file named class.java"

Numerous similar questions on SO but they do not pertain to classes generated by the AndroidX Room library. Please do not mark this question a duplicate, because similar questions relate to traditional Java classes, not those generated by…
John Harrington
  • 1,314
  • 12
  • 36
2
votes
1 answer

Inserting a List of Objects in Android Room Database with Kotlin

A Beginner in Android struggling to get around this limitation with Room Database. I'm working with two tables, Clothing, and Outfits. A user can create an Outfit by inserting the values presented to them. Then on a separate page, a user can insert…
Kyle Gerken
  • 23
  • 1
  • 1
  • 4
2
votes
2 answers

Room Database returns updated value only after app restart

i am inserting and deleting a row in room database using following methods of ViewModel class fun insert(rules: TableRules) = viewModelScope.launch { repository.insert(rules) } fun delete(id: Int) = viewModelScope.launch { …
Jignesh Ansodariya
  • 12,583
  • 24
  • 81
  • 113
2
votes
1 answer

Cause of Fatal Exception: android.database.sqlite.SQLiteException duplicate column

Getting this crash repost on Firebase Crashlytics : android.database.sqlite.SQLiteException duplicate column name: run_in_foreground (Sqlite code 1 SQLITE_ERROR): , while compiling: ALTER TABLE workspec ADD COLUMN run_in_foreground INTEGER NOT NULL…
2
votes
1 answer

onCheckedChanged is called whenever viewHolder is recycled

I am writing a todo list application and, in particular, I want the value of the checkBox to be stored in the database every time it is changed. I set this feature by adding setOnCheckedChangeListener in onBindViewHolder @Override public void…
2
votes
1 answer

Delete using inner join with composite primary key

I am trying to delete some records from my database, I have succeeded and it works when testing in "DB Browser for SQLite" software but when I try to copy it to my Android Studio project I get this error in my DAO: '(',')', '.', BETWEEN or IN…
JP711
  • 533
  • 6
  • 15
2
votes
1 answer

Android Room test with Hilt: UserDao cannot be provided without an @Provides-annotated method

I'm trying to test Room Database. For this I need an in memory instance of database. I'm using hilt for DI. So, i have an app Module in app package: @Module @InstallIn(SingletonComponent::class) object AppModule { @Singleton …
pro_go_is
  • 53
  • 1
  • 5
2
votes
2 answers

Exception while computing database live data with Enum

I have added a data class and try to save it into Room. I went through stackoverflow and didn't find an answer. So, the error is: Caused by: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was…
Seb
  • 2,929
  • 4
  • 30
  • 73
2
votes
1 answer

What happens if no records exists when I use Room to query?

I use Room in my Android Studio App, the Code A will crash when no record exists to query What happens if no records exists when I use Room to query with Code B ? @Dao interface RecordDao { // Code A @Query("SELECT * FROM record_table…
HelloCW
  • 843
  • 22
  • 125
  • 310
2
votes
1 answer

This might cause a full table scan when resolving the relationship, it is highly advised to create an index that covers this column

I have many-to-many relationship between User and Poll. While creating the relating class below I'm getting this warning on compile time: warning: The column pollId in the junction entity com.example.appproject.model.user.UserPollCrossRef is being…
2
votes
1 answer

Why instrumented room test get error FOREIGN KEY constraint failed

I don't understand this error, I have two entities Task and Project, one task is assign to one project (see code below). But when I want test to add a task, I have this error: android.database.sqlite.SQLiteConstraintException: FOREIGN KEY constraint…
2
votes
1 answer

How to abandon a manual Room migration script, and fall back to destructive migration?

In the app I'm working on, we had a complex manual migration that required data parsing, manual SQL commands, etc. This was to convert a List column into a new linked table of X. I've previously written about the approach, but the specific…
Jake Lee
  • 7,549
  • 8
  • 45
  • 86
2
votes
1 answer

SQLite/Room ORDER BY with a CASE statement ignores column COLLATE

Theres something I don't understand with regards to a CASE statement in a ORDER BY clause using SQLite (initially I was using it with Android Room but its not specific to that). This is a distillation of the problem. Query 1 returns what I was…
onbek
  • 161
  • 1
  • 7
2
votes
0 answers

how do I fix "Execution failed for task ':app:kaptDebugKotlin'"

@Database( entities = [Account::class, ExtraInfo::class], version = 2, autoMigrations = [AutoMigration(from = 1, to = 2, spec = RoomDB.AutoMigration::class)]) abstract class RoomDB: RoomDatabase() { abstract fun RoomDAO(): RoomDAO …
h j
  • 21
  • 1
  • 4
2
votes
1 answer

how to specify to not backup default sharedPreference and database with android:dataExtractionRules?

I want to not backup sharedPref as those contains login info. I'm using below code to not allow backup for API > android12.
Delowara
  • 21
  • 2