简体   繁体   English

intellij 想法内部java编译器错误

[英]intellij idea internal java compiler error

I am running a simple pattern matcher program exactly as in test_harness我正在运行一个与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

However terminal command javac xxx.java and java xxx run properly.但是终端命令javac xxx.javajava xxx运行正常。

Running the first hello world program gives the same error.运行第一个 hello world 程序会出现相同的错误。

In my case, the issue is resolved by adding a type parameter object to a class instance that needed it.就我而言,问题是通过将类型参数对象添加到需要它的类实例来解决的。 In the following code replaced new ParameterizedTypeReference<> with new ParameterizedTypeReference<Map<String, Object>>在以下代码中,将new ParameterizedTypeReference<>替换为new ParameterizedTypeReference<Map<String, Object>>

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

                                  });

It turned out that "odd" error description is because of maven plugin was missing.原来,“奇怪”的错误描述是因为缺少 maven 插件。 And it's default was 1.5 while Console class is only available since 1.6.它的默认值为 1.5,而Console类仅从 1.6 开始可用。 Instead of jar or class cannot be found , it gives a blur description internal java compiler error .jar or class cannot be found ,它给出了internal java compiler error的模糊描述。 Information:javac 1.8.0_121 was used to compile java sources was a hint that the javac version and sdk version mismatch. Information:javac 1.8.0_121 was used to compile java sources提示javac版本和sdk版本不匹配。 Besides, I was surprised that intellij idea run function uses maven build (I thought it was just for cli) .此外,我很惊讶intellij idea run 函数使用maven build (我认为它只是为了cli)。

If I have to guess, your IntelliJ is using the JDK packed with IntelliJ, try to set up your JDK for your project, in Project Structure make sure the JDK match your Java environment.如果我不得不猜测,您的 IntelliJ 使用的是与 IntelliJ 一起打包的 JDK,请尝试为您的项目设置 JDK,在项目结构中确保 JDK 与您的 Java 环境相匹配。 JDK selection JDK选择

If you use a maven project and for example, you use java version as 1.8 please use this plugin where you specify which version you are using.如果您使用 Maven 项目,例如,您使用 Java 版本为 1.8,请使用此插件,您可以在其中指定您使用的版本。 Working example:工作示例:

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM