Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does IntelliJ give me "Package doesn't exist" error?

People also ask

How do you fix package does not exist in IntelliJ?

Verify that the scope of the library (in the project structure window) is Compile . If set to a scope of Provided it will cause the behavior you describe. If you have a dependency under a maven profile, make sure you select the correct profile in the maven tree "Profiles", when you compile the project.

What does package system does not exist mean in Java?

somethingElse the compiler assumes you are doing a packageName. classname . In this case you were intending to access out of the System class, but you could very well be trying to access a package called system that is not present (in the classpath for instance). So it is a guess from a compiler.


Just reimport didn't work. Following worked for me.

File -> Invalidate Caches /Restart

Then

Build -> Rebuild Project

That will reimport maven project.

Note : You need to invalidate the cache AND ALSO rebuild the project.


I tried to "Maven > Reimport" but the only thing that actually fixed it was to close the project, delete the .idea directory, and reopen the project.


Right click your project / Maven (at bottom) / Reimport

Edit, much later: I also saw this happen much more frequently when I had the Clover plugin installed. Drop that plugin like a bad habit!


None of the 13 existing answers worked for me. However, I could resolve the issue by first removing all modules:

  1. open File > Project Structure...,
  2. go to Modules tab,
  3. select all modules and press the remove button,

then removing all remaining Maven modules from Maven tool window:

  1. select all modules,
  2. right click on them,
  3. press Remove projects,

and then adding them again in Project tool window:

  1. right click on root pom.xml,
  2. press Add as Maven project,

now unignoring any ignored modules from Maven tool window:

  1. select all ignored (grey) Maven modules,
  2. right click on them,
  3. press Unignore,

and finally rebuilding using Build > Rebuild project. This assumes that a mvn clean install already happened.