Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when trying to use Room library. [SQLITE_ERROR] SQL error or missing database

I'm trying to use the new room library but I'm getting this error

Error: There is a problem with the query: [SQLITE_ERROR] SQL error or missing database (no such table: Station)

Error: Not sure how to convert a Cursor to this method's return type

Warning: Schema export directory is not provided to the annotation processor so we cannot export the schema. You can either provide room.schemaLocation annotation processor argument OR set exportSchema to false.

Error:org.gradle.api.internal.tasks.compile.CompilationFailedException: Compilation failed; see the compiler error output for details.

enter image description here

RoomDatabase.kt

@Database(entities = TrolleyType::class), version = 2)
abstract class AppDatabase : RoomDatabase() {
    abstract fun stationDao(): StationDao
}

MyDao.kt

@Dao
interface MyDao {
    @get:Query("SELECT * FROM Station")
    val stations: List<Station>


    @get:Query("SELECT * FROM TrolleyType")
    val trolleyTypes: List<TrolleyType>
}

Entites

@Entity
data class Station(
        @PrimaryKey @ColumnInfo(name = "_id") var id: Int = 0,
        @ColumnInfo(name = "StationName") var stationName: String? = "",
        @ColumnInfo(name = "StationArabic") var stationArabic: String? = ""
)

@Entity
data class TrolleyType(
        @PrimaryKey @ColumnInfo(name = "_id") var id: Int = 0,
        @ColumnInfo(name = "Type") var stationName: String? = "",
        @ColumnInfo(name = "TypeArabic") var stationArabic: String? = ""
)
like image 795
humazed Avatar asked Jul 18 '17 14:07

humazed


1 Answers

It turns out that I just forget to add Station entity to RoomDatabase

after adding it every thing works as expected

@Database(entities = TrolleyType::class, Station::class), version = 2)
abstract class AppDatabase : RoomDatabase() {
    abstract fun stationDao(): StationDao
}
like image 63
humazed Avatar answered Nov 12 '22 01:11

humazed