当前位置: 首页 > 知识库问答 >
问题:

错误任务“:app:kaptdebugkotlin”的MyApplication执行失败

须原
2023-03-14

我有一个错误在我的应用程序,每次我看到我建立的项目它出现,我认为这是与房间的关系,但我不能解决它

日志:

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();
    }
}

类AppDatabase

@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进行数据持久化时开始发生的,我以为问题已经出现了,但从我看到的情况来看,我无法通过它的版本来修复它

共有1个答案

景成和
2023-03-14

看起来很不对劲。只需跟随google文档:

https://developer.android.com/training/data-storage/room

 类似资料: