android - java.lang.IllegalStateException : failed to analyze: com. sun.tools.javac.util.ClientCodeException : java. lang.NullPointerException 异常

标签 android kotlin java-8 illegalstateexception

我正在尝试采用 MVVM 结构来创建一些类来获得 remotelocal数据使用 repoViewModel 的帮助下上课我也在使用 DI简化流程

JDK 版本:

java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

我正在使用 java 8,定义如下:build.gradle

minSdkVersion 21
targetSdkVersion 28

compileOptions {
        targetCompatibility JavaVersion.VERSION_1_8
        sourceCompatibility JavaVersion.VERSION_1_8
    }

kotlinOptions {
    jvmTarget = JavaVersion.VERSION_1_8
}

编译时异常:

> Task :module-app:kaptDebugKotlin FAILED
e: java.lang.IllegalStateException: failed to analyze: com.sun.tools.javac.util.ClientCodeException: java.lang.NullPointerException
    at org.jetbrains.kotlin.analyzer.AnalysisResult.throwIfError(AnalysisResult.kt:56)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:123)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:166)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:56)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:84)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:42)
    at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:104)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$1$2.invoke(CompileServiceImpl.kt:442)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$1$2.invoke(CompileServiceImpl.kt:102)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:1005)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:102)
    at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:138)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:1047)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.doCompile(CompileServiceImpl.kt:1004)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:441)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
    at sun.rmi.transport.Transport$1.run(Transport.java:200)
    at sun.rmi.transport.Transport$1.run(Transport.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: com.sun.tools.javac.util.ClientCodeException: java.lang.NullPointerException
    at com.sun.tools.javac.api.ClientCodeWrapper$WrappedTaskListener.finished(ClientCodeWrapper.java:685)
    at com.sun.tools.javac.api.MultiTaskListener.finished(MultiTaskListener.java:111)
    at com.sun.tools.javac.main.JavaCompiler.enterTrees(JavaCompiler.java:987)
    at org.jetbrains.kotlin.kapt3.base.AnnotationProcessingKt.doAnnotationProcessing(annotationProcessing.kt:67)
    at org.jetbrains.kotlin.kapt3.base.AnnotationProcessingKt.doAnnotationProcessing$default(annotationProcessing.kt:36)
    at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.runAnnotationProcessing(Kapt3Extension.kt:223)
    at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.analysisCompleted(Kapt3Extension.kt:187)
    at org.jetbrains.kotlin.kapt3.ClasspathBasedKapt3Extension.analysisCompleted(Kapt3Extension.kt:98)
    at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM$analyzeFilesWithJavaIntegration$2.invoke(TopDownAnalyzerFacadeForJVM.kt:95)
    at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:105)
    at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:80)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:398)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:65)
    at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:107)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:389)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:118)
    ... 30 more
Caused by: java.lang.NullPointerException
    at org.jetbrains.kotlin.kapt3.base.incremental.TypeTreeVisitor.visitVariable(javacVisitors.kt:112)
    at org.jetbrains.kotlin.kapt3.base.incremental.TypeTreeVisitor.visitVariable(javacVisitors.kt:50)
    at com.sun.tools.javac.tree.JCTree$JCVariableDecl.accept(JCTree.java:864)
    at com.sun.source.util.SimpleTreeVisitor.visit(SimpleTreeVisitor.java:53)
    at org.jetbrains.kotlin.kapt3.base.incremental.TypeTreeVisitor.visitClass(javacVisitors.kt:75)
    at org.jetbrains.kotlin.kapt3.base.incremental.TypeTreeVisitor.visitClass(javacVisitors.kt:50)
    at com.sun.tools.javac.tree.JCTree$JCClassDecl.accept(JCTree.java:720)
    at org.jetbrains.kotlin.kapt3.base.incremental.MentionedTypesTaskListener.finished(javacVisitors.kt:39)
    at com.sun.tools.javac.api.ClientCodeWrapper$WrappedTaskListener.finished(ClientCodeWrapper.java:681)
    ... 45 more
e: java.lang.IllegalStateException: failed to analyze: com.sun.tools.javac.util.ClientCodeException: java.lang.NullPointerException
Execution failed for task ':module-app:kaptDebugKotlin'.
> Internal compiler error. See log for more details

我无法找出错误是什么?我进行了很多搜索,但仍然没有找到相关的答案。这是 Android studio 错误还是 kotlin 错误或 JDK 错误或 eny 代码相关错误

最佳答案

发现可能是文件名重复造成的。
https://discuss.kotlinlang.org/t/illegalstateexception-during-incremental-annotation-processing/14232

在我的例子中,情况略有不同(但在重复方面相似)- 由于冲突解决不当,一个类中有两个相似的伴生对象。

花了两天时间,尝试通过commits对比找出问题

关于android - java.lang.IllegalStateException : failed to analyze: com. sun.tools.javac.util.ClientCodeException : java. lang.NullPointerException 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63370848/

相关文章:

android - 如何不回收我的 recyclerview 或任何项目的前 2 个 View ?

android - 当手机横向时我想要软键盘

android - 如何在适配器中做最新的jetpack "View binding",绑定(bind) View ?

java - Java 8 Stream 中有多个正则表达式从 Line 读取文本

java - 无法更新应用程序 : Class file is Java 8 but max supported is Java 7

android - 如何去除饼图中的中心白圈

android - 在 Android 4 中设置对话框宽度

kotlin - 如何将项目添加到 Kotlin 中的 ArrayList?

android - 类型参数不在其范围内 预期 : Parcelable Found: String

android - 如何在 minsdk <24 上将 Kotlin 与 Butterknife 10.1.0 一起使用?