IntelliJ gives Fatal Error: Unable to find package java.lang in classpath or bootclasspath

Intellij IdeaClasspath

Intellij Idea Problem Overview


When I try to make a simple module in IntelliJ it responds with:

Fatal Error: Unable to find package java.lang in classpath or bootclasspath

Intellij Idea Solutions


Solution 1 - Intellij Idea

Somehow the JDK language jars were removed from the classpath. All I had to do was reapply the JSDK home path.

Goto: File -> Project Structure -> Platform Settings -> SDKs Re-apply the JSDK home path.

Doing this added about 15 jars to the classpath. Apparently these are important for compiling.

Solution 2 - Intellij Idea

File -> Project Structure -> Platform Settings -> SDKs, remove existing SDK and add it again.

Works for me in IntelliJ 2017.3.

Solution 3 - Intellij Idea

This error happend to me after i've updated my JDK version to jdk1.8.0_161 -
But the project's sdk was still pointing to the old jdk 1.8.0_131

(Seems that updgrading java causing the previous version to be wiped).

Do this:

  1. In the IntelliJ IDE go to File > Project Structure, from there:

  2. Within Platform Settings > SDKs:
    Make sure that the JDK Home path field is pointing to a valid JDK folder (add a new entry if needed e.g. jdk1.8.0_161).

  3. Within Project Settings > Modules:
    Make sure that the Module SDK is set to the same entry you picked in the Platform Settings > SDKs

  4. Save & Build again.

Solution 4 - Intellij Idea

This worked for me:

In Preferences Build Tools > Maven > Runner > Environment Variables set JAVA_HOME to your JDK home path.

Usually you want to use the same Java JDK you are using in IntelliJ. You can find that under Project Structure > Platform Settings > SDKs under JDK home path.

e.g. /Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home

Solution 5 - Intellij Idea

In Intellij Community 2019.1, this is what I did to solve the issue

  • Project Structure > Platform Settings > SDKs
  • Removed all existing SDKs listed ( I had multiple SDK listed there)
  • Add the required SDK only and Apply

Solution 6 - Intellij Idea

After following this answer, I learned that %LOCALAPPDATA%/IDEA/config/options/jdk.table.xml contained incorrect entries. Fixing the JDK table fixed the problem.

Solution 7 - Intellij Idea

  1. File > Project Structure
  2. JDK home path : PASTE_THE_JDK_LOCATION (Like here in the "Project Structure screen shot"
  1. Build Again

Cheers :)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBrigView Question on Stackoverflow
Solution 1 - Intellij IdeaBrigView Answer on Stackoverflow
Solution 2 - Intellij IdeaBabken VardanyanView Answer on Stackoverflow
Solution 3 - Intellij IdeaMercuryView Answer on Stackoverflow
Solution 4 - Intellij IdeaAndrea BergonzoView Answer on Stackoverflow
Solution 5 - Intellij IdeaSudheesh ParappurathView Answer on Stackoverflow
Solution 6 - Intellij IdeaDerMikeView Answer on Stackoverflow
Solution 7 - Intellij IdeaKumarView Answer on Stackoverflow