1

I am using Room Database to store data in my application. But, trying to compile the project, I get the following error: "Invalid query argument". I tried to find the reason in the official documentation and also googling cause of this error, but it was all to no avail. Please, could you help by explaining what this error is in general, what causes it and what I need to fix in the project?

Exact error message

C:\Users\***\ParsedDatabase.java:10: error: Invalid query argument: int. It must be a class or an interface.
public final class ParsedDatabase {
             ^

Model - ParsedDatabase (Room Database entity, class with problem)

@Entity(tableName = "parsed_database")
data class ParsedDatabase(
    @PrimaryKey()
    val id: Int = 1,
    @ColumnInfo(name = "app_config")
    val appConfigSection: HashMap<String, String>,
    @ColumnInfo(name = "loans")
    val loansList: ArrayList<Offer>,
    @ColumnInfo(name = "cards")
    val cardsList: ArrayList<ArrayList<Offer>>,
    @ColumnInfo(name = "credits")
    val creditsList: ArrayList<Offer>,
) {

    enum class AppConfigKeys {
        app_config,
        user_term_html,
        extra_field_,
    }

    enum class LoansAndCreditsKeys {
        loans,
        credits,
    }

    enum class CardsKeys {
        cards,
    }

}

Dao class (I attach just in case)

@Dao
interface LocalDatabaseDao {
    @Insert(onConflict = REPLACE)
    fun save(parsedDatabase: ParsedDatabase)

    @Query("SELECT * FROM parsed_database WHERE id = :id")
    fun load(id: Int = 1): ParsedDatabase?

    @Delete
    fun delete(parsedDatabase: ParsedDatabase)

    @Delete(entity = ParsedDatabase::class)
    fun delete(id: Int = 1)
}

Database class

@Database(entities = [ParsedDatabase::class], version = 1, exportSchema = false)
@TypeConverters(Converters::class)
abstract class LocalDatabase : RoomDatabase() {
    abstract fun getLocalDatabaseDao(): LocalDatabaseDao
}
2
  • Try removing fun delete(id: Int = 1) from your DAO. Commented Nov 4, 2021 at 12:40
  • @CommonsWare It actually worked, thanks a lot! Commented Nov 4, 2021 at 12:48

1 Answer 1

3
    @Delete(entity = ParsedDatabase::class)
    fun delete(id: Int = 1)

I do not think that Room knows what to do with this. If you need that operation, you could try:

    @Query("DELETE FROM parsed_database WHERE id = :id")
    fun delete(id: Int = 1)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.