IntelliJ on Mac Can't detect syntax errors for

2019-02-10 10:32发布

问题:

I just started using IntelliJ on Mac. The problem I met is that syntax error on my java file can't be detected and highlighted as in PC.

The problem is errors are not detected instead of errors not being highlighted, because I have checked the highlighting setting.

Any configuration I can play with to let the syntax error can be detected?

i.e.,

test = "Test"; There is no class declaration.

回答1:

I'm going to guess that your Java classes have this icon when you open them:

What this means is that your Java class file isn't in a recognized source root. IntelliJ doesn't know that this is a source file, so it won't treat it as one.

Right-click on the folder, and select "Mark Directory As" -> "Sources Root".

After that, drag and drop your Java class into that folder. Then, you'll see it appear as this:

Then IntelliJ will report all of your errors.