Android studio JavaDoc 错误抛出 NullPointerException

Android studio JavaDoc error throws a NullPointerException

Android 工作室无法创建 JavaDoc。它抛出空指针异常,无法识别任何 android 打包的项目。

...
/home/<user>/AndroidStudioProjects/<project>/app/src/main/java/com/example/simpleparadox/listycity/MainActivity.java:14: error: cannot access ViewGroup
public class MainActivity extends AppCompatActivity {
       ^
  class file for android.view.ViewGroup not found
javadoc: error - fatal error encountered: java.lang.NullPointerException
javadoc: error - Please file a bug against the javadoc tool via the Java bug reporting page
(http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com)
for duplicates. Include error messages and the following diagnostic in your report. Thank you.
java.lang.NullPointerException
    at jdk.compiler/com.sun.tools.javac.comp.TypeEnter$MembersPhase.runPhase(TypeEnter.java:934)
    at jdk.compiler/com.sun.tools.javac.comp.TypeEnter$Phase.doCompleteEnvs(TypeEnter.java:282)
    at jdk.compiler/com.sun.tools.javac.comp.TypeEnter$MembersPhase.doCompleteEnvs(TypeEnter.java:877)
    at jdk.compiler/com.sun.tools.javac.comp.TypeEnter$Phase.completeEnvs(TypeEnter.java:251)
    at jdk.compiler/com.sun.tools.javac.comp.TypeEnter$Phase.completeEnvs(TypeEnter.java:266)
    at jdk.compiler/com.sun.tools.javac.comp.TypeEnter$Phase.completeEnvs(TypeEnter.java:266)
    at jdk.compiler/com.sun.tools.javac.comp.TypeEnter$Phase.completeEnvs(TypeEnter.java:266)
    at jdk.compiler/com.sun.tools.javac.comp.TypeEnter.complete(TypeEnter.java:198)
    at jdk.compiler/com.sun.tools.javac.code.Symbol.complete(Symbol.java:642)
    at jdk.compiler/com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:1326)
    at jdk.compiler/com.sun.tools.javac.comp.Enter.complete(Enter.java:583)
    at jdk.compiler/com.sun.tools.javac.comp.Enter.main(Enter.java:560)
    at jdk.javadoc/jdk.javadoc.internal.tool.JavadocEnter.main(JavadocEnter.java:79)
    at jdk.javadoc/jdk.javadoc.internal.tool.JavadocTool.getEnvironment(JavadocTool.java:206)
    at jdk.javadoc/jdk.javadoc.internal.tool.Start.parseAndExecute(Start.java:576)
    at jdk.javadoc/jdk.javadoc.internal.tool.Start.begin(Start.java:432)
    at jdk.javadoc/jdk.javadoc.internal.tool.Start.begin(Start.java:345)
    at jdk.javadoc/jdk.javadoc.internal.tool.Main.execute(Main.java:63)
    at jdk.javadoc/jdk.javadoc.internal.tool.Main.main(Main.java:52)
7 errors


然后我找到了解决方法,即在 JavaDoc 对话框的其他命令行参数文本框中添加 -bootclasspath path_to_sdk_android_jar_file

但是,较新的 Java 已弃用 -bootclasspath。它抛出另一个错误如下:

error: option --boot-class-path not allowed with target 11

所以我改用了-sourcepath。这带来了旧错误(NullPointerException)。

此时我几乎迷路了。

顺便说一下,如果我选择一个只有 Java 元素(没有-android)的 class 并且只为那个特定文件创建 JavaDoc,它很好地创建 JavaDoc。但这对于有很多 classes 的项目来说不是一个好的解决方法。

我遇到了和你一样的问题,有几个导入错误..

以下解决方案对我有用 (我从 mike192 的答案中得到它,请参阅 link )

task javadoc(type: Javadoc) {

    doFirst {
        configurations.implementation
                .filter { it.name.endsWith('.aar') }
        .each { aar ->
            copy {
                from zipTree(aar)
                include "**/classes.jar"
                into "$buildDir/tmp/aarsToJars/${aar.name.replace('.aar', '')}/"
            }
        }
    }

    configurations.implementation.setCanBeResolved(true)
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    classpath += configurations.implementation
    classpath += fileTree(dir: "$buildDir/tmp/aarsToJars/")
    destinationDir = file("${project.buildDir}/outputs/javadoc/")
    failOnError false
    exclude '**/BuildConfig.java'
    exclude '**/R.java'
}

您需要做的就是将代码添加到您的 build.gradle 文件中,就在您的依赖项 {}

之前

然后,双击 Ctrl 按钮并执行以下命令:

gradle javadoc

然后可以在您的项目目录中找到 javadoc 的结果 \app\build\outputs\javadoc

我希望这对你有用