51

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:

Activated Inspections

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

Kindly help me solve this problem.

4
  • 2
    Show your editor where the code is not highlighted. Commented Apr 9, 2017 at 14:27
  • I have edited my post by adding a new screenshot available here: link to screenshot of my code Commented Apr 10, 2017 at 9:16
  • Why do you expect an error on the main(String[] args) line? Just because it isn't a valid entry point for your Java program doesn't mean that this method is invalid altogether. Commented Apr 10, 2017 at 9:31
  • 1
    @Tom there isn't a return type. Commented Jun 1, 2018 at 17:09

13 Answers 13

95

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

java project

source root

Sign up to request clarification or add additional context in comments.

1 Comment

Having been used to pycharm, I falsely assumed that syntax highlighting & error handling would work everywhere in IntelliJ
49

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

File Menu -> Power Saver Mode

2 Comments

Saved my life. The day before Intellij was killing my CPU and it prompts for Power saver mode which I gladly enabled...
saved my life also . When did this get on I never had a clue
22

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!

Comments

7

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.

Comments

2

In my case none of these solutions were solving my problem, but I knew that I had been able to get error highlights when I started working on the project so I deleted the .idea folder in the project folder, reopened IntelliJ, and got back my errors. No clue as to what could have happened

Comments

1

I was getting the same issue, I just clicked on the re-import button on the maven panel and it solved the problem .

2 Comments

Please provide detail/elaborate answer because currently it looks like a comment, when you have 50 rep you will be able to comment.
i guess - right click on pom.xml -> maven -> reload project (in modern idea) Or Maven panel in the right side, the button with 2 cycled arrows "Reload All Maven Projects"
1

In my case, just Reloading the project solved it.

Right Click on Root folder -> Maven -> Reload Project

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
0

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.

Comments

0

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.

Comments

0

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

Comments

0

Sometimes, this happens when the IDE is in a inconsistent or an error state.

You can find out the reason by looking at the Intellij logs from Help -> Show Log in Files and see if you see any exception there.

One possible reason could be that a plugin is interfering in the normal flow causing a buggy condition that disables the file syntax highlighting and error checking. Disabling the offending plugin should take care of that problem.

Another possible reason is that the intellij caches are corrupted in which case simply "Invalidate Caches" from the file menu should do the trick

Comments

0

Although I had Editor > Inspections enabled on my Settings, I had disabled it for certain files a while ago and forgot about it!

Hover the Inspections widget (compact view) in the top-right corner of the editor and select the desired highlighting level from the Highlight list.

Highlighting level on the Inspections widget

Options:

  • None: turns off all highlighting
  • Syntax: highlights only syntax problems
  • All Problems: (default) highlights syntax problems and problems found by inspections.

Docs:

Comments

0

Recently I had the same problem with Idea2025.2. The solution was to delete the ~/.local/share/JetBrains/IdeaIC2025.2 directory and re-install the plugings.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.