Reputation: 81
In my DAO associated to the room injected by Hilt into a ViewModel and is carrying a data class entity "FoodMenu" which contains an array of objects which inturn use a type converter shows error on using @Query but works fine with @Insert or @Delete.
My Dao
@Dao
interface MenuDAO {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun addMenu(element:FoodMenu):Unit
//If i comment out the below @Query..... section. There is no error
@Query("SELECT * FROM menu")
fun getMenu():List<FoodMenu>
}
AppDatabase
@Database (entities=[Cart::class,FoodMenu::class],version = 1,exportSchema = false)
@TypeConverters(TypeConverter::class)
abstract class AppDatabase : RoomDatabase() {
abstract fun menuDAO():MenuDAO
}
Data Class and type converter
data class Food(
var name:String,
var price:Int,
var image:String,
)
@Entity(tableName="menu")
data class FoodMenu(
@PrimaryKey
var category:String,
var list:List<Food>
)
class TypeConverter{
@TypeConverter
fun fromFoodList(value:List<Food>?)= Gson().toJson(value)
@TypeConverter
fun toFoodList(value:String)= Gson().fromJson(value,Array<Food>::class.java).toList()
}
MY ERROR
> Task :app:kaptDebugKotlin FAILED
Execution failed for task ':app:kaptDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
> java.lang.reflect.InvocationTargetException (no error message)
Upvotes: 1
Views: 168
Reputation: 174
Press parent Build section when error occurs it shows cause of the error as explained in the link
Upvotes: 0