18

I recently downloaded IntelliJ IDEA to a different computer. On one computer it works fine on the other computer it is giving me this current issue.

When i open a new project with a template it automatically shows errors everywhere even though it allows the code to run and shows the output correctly: standard Java library classes like String and System are highlighted in red and the error tooltip says: "cannot resolve symbol".

I have tried "Invalidate caches/Restart", but it didn't help.

Basic code showing errors in JDK classes

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
Thompson
  • 183
  • 1
  • 1
  • 4

7 Answers7

40

Check the JDK configuration Classpath tab in Project Structure | SDKs:

JDK

Also check that project and modules use the same JDK.

If it's empty, remove the JDK and add it again. It's not recommended to use JetBrains Runtime as your JDK, download and configure some different standalone JDK instead, 2020.1 version can download JDK for you.

Important notice The bundled JRE is used for running the IDE itself, and it's not sufficient for developing Java applications. Before you start developing in Java, download and install a standalone JDK build.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
7

I tried above, but no luck. I did get it working with File -> Invalidate Caches... I selected all three checkboxes and then "Invalidate and Restart". That worked for me.

BBNKSR
  • 71
  • 1
  • 1
0

Often this means there is an issue with your java compiler. Normally this issue arises on an initial Intellij install. You can install/update the java compiler to get it working properly.

Go to the editor and type Ctrl + Alt + Shift + A . Then, a little bar pops down and you can select to either install the compiler, or configure it. Both times this happened to me, I just clicked install and once it was done, everything worked. If the install doesn't work, you can just reconfigure your compiler.

Jeremy
  • 1,038
  • 11
  • 34
0

Removing the Java SDK and adding it back under File->Project Structure did it for me.

0

The only thing that worked for me (after hours of trying!) was to use the Android Studio's embedded JDK. "Invalidate caches/Restart" did not solve the issue, even using the same JDK version which was not coming with Android Studio was giving the Cannot resolve symbol 'String' errors. Wonder what's so special with this pre-packaged JDK! Hmmm

doctorram
  • 1,112
  • 14
  • 13
0

For me the solution seems to have been creating a new Run Configuration.

I had tried deleting the SDKs, and re-adding the one I needed but that did not clear the error. But creating a new Run Configuration did the trick.

cptully
  • 615
  • 1
  • 9
  • 24
-1

I had this problem when I uninstalled JDK and re installed it, and when I was making a new project I had the uninstalled JDK file selected, which somehow caused the system to be in red and un run-able.

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 29 '22 at 12:17
  • What is the solution? – IgorGanapolsky Jan 06 '23 at 20:06