简体   繁体   中英

Auto errors detection in IntelliJ IDEA

I am new to Java programming language and the 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.

This image displays the activated inspections:

激活检查

This is a screenshot of my code with multiple errors but no detected by the IDE: 我的代码截图

Kindly help me solve this problem.

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 roots so that it resides under the folder configured as the Sources root.

Sources root 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):

项目

源根

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

File Menu -> Power Saver Mode

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.

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

1. Go to Project Structure and Select Project

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

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. Project Language Level: I chose “SDK Default”

2. Go to Project Structure and Select Modules

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

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

c. Click ok.

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

a. Select + at the top left hand corner.

b.Select “Application”

c. Change the name to “Main”

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

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

This should work!

Try this :

1. Invalidate caches and restart IntelliJ

File -> Invalidate Caches / Restart... -> Invalidate and Restart

2. Desactive the Power Saver Mode

File Menu -> Power Saver Mode

It works for me.

If you use a build system (Maven, Gradle, etc.):

Open its panel in IntelliJ, then click the reimport button. For Gradle, this button looks like a sync icon and its hovertext says "Reload All Gradle Projects".

Why it works:

Since the build system is in charge of compiling your code, it knows which files are source code. It would be a waste of computing power to look for missing semicolons in a compiled binary file, so IntelliJ won't try to find errors until it knows the file is source code.

Most build systems, Maven and Gradle included, are also dependency managers. When you write code that uses libraries or depends on a different module, IntelliJ needs to be able to understand the dependency to tell you whether your code makes sense, or whether you made a mistake like forgetting an import statement or passing the wrong type of argument into a library function. When IntelliJ doesn't understand your dependencies, it displays all your uses of imported code in red text.

我遇到了同样的问题,我只是点击了maven面板上的re-import按钮,它解决了问题。

It is very simple. You have just to go to the "File" and deactivate "Power Save Mode"

I had the same issue and here it is how I solved it: Some files where ignored and I Unignored them. To do this go to Maven tab on the right panel -> right click on each project that is in grey color and click Unignore projects.

I'll add an another reason for it. For me it was Reader mode enabled. I was not even been aware of its existence. Can be disabled in Settings -> Editor -> Reader mode.

In my case was a maven option, When you open the proyect in intellij. it create a notification.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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