140

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
lospejos
  • 1,976
  • 3
  • 19
  • 35
Brig
  • 10,211
  • 12
  • 47
  • 71

7 Answers7

256

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.

Brig
  • 10,211
  • 12
  • 47
  • 71
  • 2
    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). – Matt Aug 17 '11 at 19:10
  • I think this happened when I added the same jdk again. It removed all of the references from the original jdk :/ – Boushley Feb 05 '12 at 07:26
  • 2
    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! – James Wald Feb 15 '12 at 21:45
  • 44
    JetBrains should fix this lame bug. – expert Nov 06 '12 at 09:29
  • I've run into this with IntelliJ IDEA 12.1.3, so not fixed, yet – Kaffee Jun 13 '13 at 08:43
  • Just hit this in 13.1.4, still not fixed. Thank you for the workaround. – Splaktar Aug 13 '14 at 04:29
  • for reapplying the JSDK, I had to remove and add it again – JoachimR Dec 22 '14 at 13:34
  • 8
    This bug still exists! – Frankie Drake Dec 25 '14 at 16:25
  • Confirmed this bug still exists, version 14.1.4 – FreeDevz Jul 20 '15 at 04:50
  • @FreeDevz 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 ? – kuldeep Aug 20 '15 at 08:07
  • 1
    Year 2016, the 'bug' stile alive. – streak May 06 '16 at 10:40
  • 4
    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.3 – mtber75 Dec 01 '16 at 14:09
  • Also if there are still errors, you could goto project settings > project and point 'project SDK' to added SDK – merlachandra Dec 19 '17 at 06:59
  • 1
    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. – lospejos Jan 12 '18 at 11:05
  • 2
    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. – Gazihan Alankus Feb 01 '18 at 12:37
  • Thanks, Applying JDK home path again, helped – Ajitsen Oct 25 '18 at 05:13
  • IntelliJ IDEA 2018.3 (Community Edition) - problem still exists. Your tip helped me, thanks! – wojand Nov 22 '18 at 13:38
  • 2
    IntelliJ IDEA 2018.3.3 (Ultimate Edition) problem still exists, thanks. – m.w. Jan 23 '19 at 18:36
  • IntelliJ IDEA 2019.1.1 problem still exists – santosh kumar May 13 '19 at 17:46
  • (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.) – Tonsic Aug 22 '19 at 17:13
  • I can't believe it's been 10 years. Here's to another 10! – Brig Feb 02 '21 at 22:48
  • yes, problem still occurs – Marek Bernád Oct 14 '21 at 11:13
20

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

Works for me in IntelliJ 2017.3.

Babken Vardanyan
  • 14,090
  • 13
  • 68
  • 87
  • This problem happened to me once after upgrading jdk (only the patch number), removing and adding again did make everything compile again. – qed Apr 04 '18 at 08:56
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.
Mercury
  • 7,430
  • 3
  • 42
  • 54
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

Andrea Bergonzo
  • 3,983
  • 4
  • 19
  • 31
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
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 :)

Kumar
  • 51
  • 4
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.

Community
  • 1
  • 1
DerMike
  • 15,594
  • 13
  • 50
  • 63