Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

intellij idea - Java Fatal Error: Unable to find package java.lang in classpath or bootclasspath

I'm getting this error

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

in IntelliJ when I try to build/compile any project. Something that should be stated here is that NetBeans, Eclipse and even the javac command line can compile, build, and execute the same project without errors. This is why I suspect that the problem lies with IntelliJ, all other IDEs work well.

In IntelliJ I already:

Restarted, reinstalled Invalidate Caches / restarted Deleted / readded the JDK in Project JDK Deleted / readded the JDK in Platform Settings Rebuild / recompile

In Windows I already:

Deleted / Reinstalled Java SDK Deleted / Readded the JAVA_HOME, PATH and CLASSPATH on System Variables Tried the above on User Variables Deleted and reinstalled IntelliJ IDEA

I already seached for issues like this on the Internet, here on Stack Overflow I found:
Question #1 | Question #2 | Question #3 | Question #4 | Question #5
And 30+ sites, and tried every answer...
Here you can see my IntelliJ Project Structure the last time that I tried to build/compile

I was using Java 1.8 when I got this error, after some hours, I installed Java 1.7 and the project worked fine. Maybe IntelliJ doesn't support Java 1.8?

Anyway, it would be great if anyone knew a way to make Java 1.8 work with IntelliJ.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I just spent quite few hours on this and found a solution which might work for you as well. IntelliJ seems to have a bug which expects the JDK to be in a different directory than is specified. I followed these steps:

  • open intelliJ, click help -> show log in explorer
  • modify build-log/build-log.xml and change <priority value="info" /> to <priority value="debug" />, you may have to run the editor as an administrator
  • run the compilation which fails with "Error:java: Fatal Error: Unable to find..."
  • open build-log/build.log and search for rt.jar, you should find it in a block with a set of other JRE libraries and the directory which points to the file should be wrong

In my case the JDK is included in D:Developmentsoftwarejdk1.8.0_20, while the log points to C:UsersVladimirDevelopmentsoftwarejdk1.8.0_20

I fixed the issue by copying my JRE to the place which is expected in the log. And just like in your case this seems to only happen with JDK 1.8.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...