Java IntelliJ IDEA 中的自动错误检测

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43307532/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 00:51:02  来源:igfitidea点击:

Auto errors detection in IntelliJ IDEA

javaintellij-ideajetbrains-ide

提问by Prince Lionel N'zi

I am new to Java programming language and the IntelliJ IDEA 2017.1 IDE.

我是 Java 编程语言和 IntelliJ IDEA 2017.1 IDE 的新手。

I just installed the IDE and I activated all the various inspections but the IDE is unable to detect the errors any time I make a mistake such as omitting a bracket or a semicolon.

我刚刚安装了 IDE 并激活了所有各种检查,但 IDE 无法在我犯错误(例如省略括号或分号)时检测到错误。

This image displays the activated inspections:

此图像显示激活的检查:

Activated Inspections

激活检查

This is a screenshot of my code with multiple errors but no detected by the IDE: screenshot of my code

这是我的代码的屏幕截图,其中包含多个错误,但 IDE 未检测到: 我的代码截图

Kindly help me solve this problem.

请帮我解决这个问题。

采纳答案by CrazyCoder

Java file is not analyzed since it's located outside of the source root. You need to either relocate the file or reconfigure your content rootsso that it resides under the folder configured as the Sourcesroot.

Java 文件不会被分析,因为它位于源 root 之外。您需要重新定位文件或重新配置您的内容根目录,使其位于配置为根目录的文件夹下。

Sourcesroot is marked in blue in the project view. Here is the example of the properly configured project (notice the class icon is different than on your screenshot):

根在项目视图中标记为蓝色。这是正确配置的项目的示例(请注意类图标与屏幕截图上的不同):

java project

项目

source root

源根

回答by user9944315

This is finally what worked for me! Phew! My Problem: Whenever I exit Intellij and try to open up an old/existing project, I have trouble getting the builds and execute to work on my localhost. I'm just using localhost.

这终于对我有用了!呼!我的问题:每当我退出 Intellij 并尝试打开一个旧的/现有的项目时,我都无法获取构建并在我的本地主机上执行。我只是使用本地主机。

Here are the steps that finally worked on my localhost environment:

以下是最终在我的本地主机环境中工作的步骤:

1. Go to Project Structure and Select Project

1.转到项目结构并选择项目

a. Set the SDK to 10 (“Java Version 10.0.2”) or whatever you are using.

一种。将 SDK 设置为 10(“Java 版本 10.0.2”)或您正在使用的任何值。

b. (I think this was the main step I was missing) Set the project compiler output to point to where I want the compiled output to sit: C:\Users\kbala\OneDrive - MatrixCare\SoftWLearnings\Javamyfun\NewHelloWorld\out

湾 (我认为这是我遗漏的主要步骤)将项目编译器输出设置为指向我希望编译输出所在的位置:C:\Users\kbala\OneDrive - MatrixCare\SoftWLearnings\Javamyfun\NewHelloWorld\out

c. Project Language Level: I chose “SDK Default”

C。项目语言级别:我选择了“SDK Default”

2. Go to Project Structure and Select Modules

2. 进入项目结构并选择模块

a. Click on src (this is where my source code sits).

一种。单击 src(这是我的源代码所在的位置)。

b. Then, Click on the “Sources” folder icon on the top. This adds src to the “Source folders” on the right. You will see the color change to Blue

湾 然后,单击顶部的“Sources”文件夹图标。这会将 src 添加到右侧的“源文件夹”。您将看到颜色变为蓝色

c. Click ok.

C。单击确定。

3. Then, click on “Add Configuration” (top right corner of Intellij)

3.然后,点击“添加配置”(Intellij的右上角)

a. Select + at the top left hand corner.

一种。选择左上角的 +。

b. Select “Application”

湾 选择“申请”

c. Change the name to “Main”

C。将名称更改为“主要”

d. Now click on the Ellipsis (three dots) in “Main Class”. You should now see your Main Class. Select it.

d. 现在单击“主类”中的省略号(三个点)。您现在应该看到您的主类。选择它。

e. You should now see the execute arrow at that top right of Intellij. And you should see the build icon (Hammer).

e. 您现在应该在 Intellij 的右上角看到执行箭头。您应该会看到构建图标 (Hammer)。

This should work!

这应该有效!

回答by Govinda Sakhare

One more reason could be IntelliJ is running on power saver mode, this could be disabled following way:

另一个原因可能是 IntelliJ 在省电模式下运行,这可以通过以下方式禁用:

File Menu -> Power Saver Mode

File Menu -> Power Saver Mode

回答by ankit rawat

I was getting the same issue , I just clicked on the reimport button on the maven pannel and it solved the problem .

我遇到了同样的问题,我只是点击了 Maven 面板上的重新导入按钮,它解决了问题。