简体   繁体   English

IntelliJ IDEA:String、System 和其他 Java 类的“无法解析符号”

[英]IntelliJ IDEA: "cannot resolve symbol" for String, System and other Java classes

I recently downloaded IntelliJ IDEA to a different computer.我最近将 IntelliJ IDEA 下载到另一台计算机上。 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".当我使用模板打开一个新项目时,它会自动在所有地方显示错误,即使它允许代码运行并正确显示 output:标准 Java 库类(如StringSystem )以红色突出显示,错误工具提示显示:“无法解析符号”。

I have tried "Invalidate caches/Restart", but it didn't help.我试过“使缓存无效/重新启动”,但没有帮助。

显示 JDK 类中错误的基本代码

Check the JDK configuration Classpath tab in Project Structure |检查项目结构中的JDK配置类路径选项卡| SDKs:开发工具包:

JDK

Also check that project and modules use the same JDK.还要检查项目模块是否使用相同的 JDK。

If it's empty, remove the JDK and add it again.如果为空,请删除 JDK 并重新添加。 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 .不建议使用 JetBrains Runtime 作为您的 JDK,请下载并配置一些不同的独立 JDK,2020.1 版本可以为您下载 JDK

Important notice The bundled JRE is used for running the IDE itself, and it's not sufficient for developing Java applications.重要提示捆绑的 JRE 用于运行 IDE 本身,不足以开发 Java 应用程序。 Before you start developing in Java, download and install a standalone JDK build.在开始在 Java 中进行开发之前,请下载并安装一个独立的 JDK 版本。

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".我确实让它与 File -> Invalidate Caches 一起使用......我选择了所有三个复选框,然后选择了“Invalidate and Restart”。 That worked for me.这对我有用。

Often this means there is an issue with your java compiler.这通常意味着您的 java 编译器存在问题。 Normally this issue arises on an initial Intellij install.通常,此问题出现在初始 Intellij 安装时。 You can install/update the java compiler to get it working properly.您可以安装/更新 java 编译器以使其正常工作。

Go to the editor and type Ctrl + Alt + Shift + A . Go 到编辑器并键入Ctrl + Alt + Shift + A Then, a little bar pops down and you can select to either install the compiler, or configure it.然后,弹出一个小栏,您可以 select 安装编译器或配置它。 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.如果安装不起作用,您可以重新配置编译器。

Removing the Java SDK and adding it back under File->Project Structure did it for me.删除 Java SDK 并将其添加回 File-> Project Structure 下为我做了。

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.唯一对我有用的方法(经过数小时的尝试。)是使用 Android Studio 的嵌入式 JDK,即使使用 Android Studio 提供的相同 JDK 版本,“缓存无效/重启”也没有解决问题Cannot resolve symbol 'String'错误。 Wonder what's so special with this pre-packaged JDK!想知道这个预打包的 JDK 有什么特别之处! Hmmm

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.我曾尝试删除 SDK,然后重新添加我需要的 SDK,但这并没有清除错误。 But creating a new Run Configuration did the trick.但是创建一个新的运行配置就可以了。

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.当我卸载JDK并重新安装它时遇到了这个问题,当我制作一个新项目时我选择了卸载的JDK文件,这不知何故导致系统处于红色并且无法运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM