Android 构建显示无错误消息在 DAO 中使用@Query 方法时出错
Android Build shows No error message Error on using @Query method in DAO
在我的 DAO 中,该房间与 Hilt 注入到 ViewModel 中的房间相关联,并且正在携带数据 class 实体
“FoodMenu”包含一组使用类型转换器的对象,在使用@Query 时显示错误,但在使用@Insert 或@Delete 时可以正常工作。
吾道
@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
}
数据Class和类型转换器
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()
}
我的错误
> 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)
发生错误时按父构建部分,它会显示错误原因,如 link
中所述
在我的 DAO 中,该房间与 Hilt 注入到 ViewModel 中的房间相关联,并且正在携带数据 class 实体 “FoodMenu”包含一组使用类型转换器的对象,在使用@Query 时显示错误,但在使用@Insert 或@Delete 时可以正常工作。
吾道
@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
}
数据Class和类型转换器
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()
}
我的错误
> 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)
发生错误时按父构建部分,它会显示错误原因,如 link
中所述