PRVS
PRVS

Reputation: 1690

Intellij - Errors JAVA (imports, etc...) doesn't detect

I'm starting use the IntelliJ-IDEA, but my java files doesn't detect errors like imports for example. I don't create one project java, because i'm using different languages in same project, but I want that in the java files, he detect the errors. How can I make this?

Upvotes: 1

Views: 9441

Answers (4)

Shreyansh Jain
Shreyansh Jain

Reputation: 422

  • Go to File -> Project Structure -> Platform Settings -> SDKs.
  • Remove the SDK you're using by clicking on "-" sign.
  • Add the SDK you want to use by clicking on "+" sign. You can also add the same SDK that you removed in previous step.
  • Apply.

Upvotes: 0

Mohamed Dernoun
Mohamed Dernoun

Reputation: 825

I have the same problem where Intellij doesn't detect even a String, When your Intellij behaves abnormally, finds errors where there are none, outdated debugging, etc. It may be necessary to invalidate its cache (which is easily corruptible). You go to:

Intellij Invalidate Caches...

And select Clear file system cache option

Intellij clear file system cache

After clicking on Invalidate and Restart the problem should be resolved.

Upvotes: 1

AbhijithKA
AbhijithKA

Reputation: 76

In my case only java.* imports were not detected.

  • I am using gradle - java 11 (Spring boot)

These are the steps I did

  • File -> Project Structure
  • Changed the Project SDK from adopt-open-jdk11 to Amazon-coretto-11
  • Click Apply

Upvotes: 0

JockX
JockX

Reputation: 2136

Intellij can work very well standard project layouts. If yours is not standard - tell Intellij how it is structured: from open workspace, select File -> Project Structure (Ctrl+Alt+Shift+S), and go through all the tabs to setup specifics:

The most important tabs are probably:

  1. Project tab, where you specify jdk to use with the project (JAVA_HOME if you will)
  2. Modules -> Sources where you tell intellij which directories should be treated as java packages
  3. Modules -> Paths to setup where you want to put compiled classes
  4. Modules -> Libraries - to specify any additional jars to be used.

Assume you have two java files in your project:

package com.myproject // this one have package

public class SomeClass{
    //whatever
}

and

public class Main {
    // whatever - no package
}

so you should have them inside some directory:

directory
  |- com
  |  |- mypackage
  |     |- SomeClass.java
  |- Main.java

In such structure - the directory is sources root. Mark it as such

Upvotes: 2

Related Questions