gpt4 book ai didi

android - 在Dao中使用@Query时,房间[exception:KaptExecution]

转载 作者:行者123 更新时间:2023-12-02 13:25:44 25 4
gpt4 key购买 nike

由于我未知的原因,将@Query添加到我的房间后,我的应用将无法构建。
我通过逐步执行所有操作来弄清楚它是@Query,最终在我添加@Query函数时出现了错误。
我得到的错误是:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:kaptDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
> java.lang.reflect.InvocationTargetException (no error message)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
这是我的代码:
MainDatabase.kt
import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import my.test.movieexpert.localdatasource.dao.PopularMovieDao
import my.test.movieexpert.profilescreen.model.PopularMovie

@Database(entities = [PopularMovie::class], version = 1, exportSchema = false)
abstract class MainDatabase : RoomDatabase() {

abstract fun popularMovieDao(): PopularMovieDao

companion object {
@Volatile
private var Instance: MainDatabase? = null

fun getInstance(context: Context): MainDatabase {
val tempInstance = Instance
if (tempInstance != null) {
return tempInstance
}

synchronized(this) {
val instance = Room.databaseBuilder(
context.applicationContext,
MainDatabase::class.java,
"main_database"
).build()
Instance = instance
return instance
}
}
}
}
PopularMovieDao.kt =>每当我取消注释任何@Query函数时,我的应用程序都无法构建
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query

@Dao
interface PopularMovieDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun addMovies(listOfMovies: List<PopularMovie>)

// @Query("DELETE FROM PopularMovie")
// suspend fun clearTable()

// @Query("SELECT * FROM PopularMovie")
// suspend fun getMovies(): List<PopularMovie>
}
PopularMovie.kt
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.squareup.moshi.Json

@Entity
data class PopularMovie(
@field:Json(name = "id") val id: Int,
@field:Json(name = "title") val title: String,
@field:Json(name = "overview") val overview: String,
@field:Json(name = "release_date") val release_date: String,
@field:Json(name = "poster_path") val poster_path: String,
@field:Json(name = "vote_average") val vote_average: String
) {
@PrimaryKey(autoGenerate = true)
var rowId: Int = 0
}

最佳答案

找到了问题。
在我的应用程序build.gradle中,我具有以下内容:

configurations.all() {
resolutionStrategy.force "org.antlr:antlr4-runtime:4.5.3"
resolutionStrategy.force "org.antlr:antlr4-tool:4.5.3"
}
过去,我将其用于DataBinding和Room之间的兼容性错误,并且不再需要它。

关于android - 在Dao中使用@Query时,房间[exception:KaptExecution],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64160945/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com