【发布时间】:2021-04-06 22:45:02
【问题描述】:
我的MyApplication有错误,每次看到我构建的项目出现,我觉得和房间有关系但是我解决不了
日志:
Task :app:kaptDebugKotlin FAILED
C:\Users\matheus.correa_est\Desktop\Pokedex-
master\app\build\tmp\kapt3\stubs\debug\com\example\pokedex\MyApplication.java:13: error: cannot find
symbol
public final AppDataBase getDataBase() {
^
symbol: class AppDataBase
location: class MyApplication
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
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.5/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 2s
24 actionable tasks: 1 executed, 23 up-to-date
MyApplication.java
package com.example.pokedex;
import java.lang.System;
d2 = {"Lcom/example/pokedex/MyApplication;", "Landroid/app/Application;", "()V", "dataBase",
"LAppDataBase;", "getDataBase", "()LAppDataBase;", "dataBase$delegate", "Lkotlin/Lazy;",
"repository", "Lcom/example/pokedex/repository/PokedexRepository;", "getRepository", "
()Lcom/example/pokedex/repository/PokedexRepository;", "repository$delegate", "app_debug"})
public class MyApplication extends android.app.Application {
@org.jetbrains.annotations.NotNull()
private final kotlin.Lazy dataBase$delegate = null;
@org.jetbrains.annotations.NotNull()
private final kotlin.Lazy repository$delegate = null;
@org.jetbrains.annotations.NotNull()
public final AppDataBase getDataBase() { // line where the error is being shown in the log
return null;
}
@org.jetbrains.annotations.NotNull()
public final com.example.pokedex.repository.PokedexRepository getRepository() {
return null;
}
public MyApplication() {
super();
}
}
类应用数据库
@Database(entities = [PokemonItem::class], version = 1, exportSchema = false)
abstract class AppDataBase: RoomDatabase() {
abstract fun pokemonDAO(): PokemonDAO
companion object {
@Volatile
private var INSTANCE: AppDataBase? = null
fun getDataBase(context: Context): AppDataBase {
return INSTANCE ?: synchronized(this) {
val instance = Room.databaseBuilder(
context.applicationContext,
AppDataBase::class.java,
"pokemon-db"
)
.build()
INSTANCE = instance
instance
}
}
}
}
自从我将 AppDatabase 用于数据持久性以来,此错误开始发生,我认为问题出在 gradle 中,但据我所见,我无法通过其版本修复它
【问题讨论】:
标签: java android kotlin android-room