intellij idea内部java编译器错误

时间:2018-02-06 02:21:05

标签: java intellij-idea

我正在运行一个简单的模式匹配程序 test_harness

Information:java: Errors occurred while compiling module 'demo_java8'
Information:javac 1.8.0_121 was used to compile java sources
Information:2018-02-06 10:15 - Compilation completed with 1 error and 0 warnings in 376ms
Error:java: Compilation failed: internal java compiler error

但终端命令javac xxx.javajava xxx正常运行。

运行第一个hello world程序会产生同样的错误。

4 个答案:

答案 0 :(得分:1)

原来,“奇怪”的错误描述是因为maven插件丢失了。它的默认值为1.5,而Console类仅在1.6之后可用。它不是jar or class cannot be found,而是提供模糊描述internal java compiler errorInformation:javac 1.8.0_121 was used to compile java sources暗示javac版本和sdk版本不匹配。此外,我很惊讶intellij idea运行函数使用maven build(我以为它只是用于cli)。

答案 1 :(得分:0)

如果我不得不猜测,你的IntelliJ正在使用随IntelliJ打包的JDK,尝试为项目设置JDK,在Project Structure中确保JDK与您的Java环境匹配。 Regex

答案 2 :(得分:0)

就我而言,通过将类型参数对象添加到需要它的类实例中,可以解决此问题。在以下代码中,将new ParameterizedTypeReference<>替换为new ParameterizedTypeReference<Map<String, Object>>

return getRestTemplate().exchange(uri,
                                  HttpMethod.POST,
                                  new HttpEntity<>(headers),
                                  new ParameterizedTypeReference<Map<String, Object>>() {

                                  });

答案 3 :(得分:0)

例如,如果您使用的是Maven项目,则使用Java版本为1.8,请在指定使用哪个版本的地方使用此插件。 工作示例:

<dependencies>
    <dependency>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>