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

7

141

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
Sihun answered 15/6, 2010 at 22:10 Comment(0)
S
257

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.

Sihun answered 15/6, 2010 at 22:32 Comment(19)
Thanks, I just ran in to this and your fix worked for me as well. I somehow triggered the issue when adding and removing some SDKs (I have multiple versions of the JDK installed on my machine).Gratifying
I think this happened when I added the same jdk again. It removed all of the references from the original jdk :/Bole
I didn't change anything with my IDE or SDK but system updates may have touched that. Re-applying the JSDK home path worked. Thanks!Calliopsis
JetBrains should fix this lame bug.Magnificat
I've run into this with IntelliJ IDEA 12.1.3, so not fixed, yetWarrington
Just hit this in 13.1.4, still not fixed. Thank you for the workaround.Deboradeborah
for reapplying the JSDK, I had to remove and add it againOutbuilding
Confirmed this bug still exists, version 14.1.4Percipient
@Percipient stumbled across the same error, but looks like the menu options have changed, can not find platform settings and SDKs options in the project structure ! Any idea where to find this resetting of JSDK ?Moe
What do you mean by "reapplying". I removed my old JSDK and added it again, but it does not work. I am using Java 2016.3Variegated
Also if there are still errors, you could goto project settings > project and point 'project SDK' to added SDKWhilom
Just caught this bug in Idea 2017.3.2. Reapplied jdk by hittling path selecting button (with 3 dots on button caption) and selecting again the same path to JDK.Biotype
Reporting from year 2018, with IDEA Ultimate 2017.3.4, the bug is still alive and well :) Reapplying it once after installation in Ubuntu was sufficient.Antipyretic
Thanks, Applying JDK home path again, helpedTortola
IntelliJ IDEA 2018.3 (Community Edition) - problem still exists. Your tip helped me, thanks!Tang
IntelliJ IDEA 2018.3.3 (Ultimate Edition) problem still exists, thanks.Magenta
IntelliJ IDEA 2019.1.1 problem still existsCloy
(btw, it is happening to me even when calling gradle from terminal in a specific project here. So, at least in my case, it is more probable that it is some gradle config in the project or the fact that this project's gradle version is pre-historic. So if you are using gradle also, watch out for this possibility. Reapply here didn't work of course.)Tenaculum
yes, problem still occursSagunto
V
21

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

Works for me in IntelliJ 2017.3.

Verein answered 13/1, 2018 at 15:9 Comment(1)
This problem happened to me once after upgrading jdk (only the patch number), removing and adding again did make everything compile again.Maximilien
F
13

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.
Finn answered 14/2, 2018 at 11:51 Comment(0)
A
5

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

Audacious answered 28/10, 2017 at 0:15 Comment(0)
N
4

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
Nicky answered 8/10, 2020 at 14:21 Comment(0)
A
1
  1. File > Project Structure
  2. JDK home path : PASTE_THE_JDK_LOCATION (Like here in the "Project Structure screen shot"

  3. Build Again

    Cheers :)

Alcine answered 26/5, 2018 at 16:54 Comment(0)
B
0

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

Barrel answered 11/2, 2016 at 16:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.