简体   繁体   English

无法使用 Intellij IDEA 运行 Java 代码(通过打开项目)

[英]Fail to run Java code (by opening a project) with Intellij IDEA

I am new to the IDE.我是 IDE 的新手。 I have installed Java SE Development Kit 13.0.1 and set it as my JDK installation.我已经安装了 Java SE Development Kit 13.0.1 并将其设置为我的 JDK 安装。

I opened a project (.java file) and the code was successfully shown.我打开了一个项目(.java 文件)并成功显示了代码。 But the main run is greyed out and I can't run my code.但是主要运行是灰色的,我无法运行我的代码。

May I know how can I solve it?我可以知道我该如何解决吗? Thanks for your help!谢谢你的帮助!

屏幕

I think, your source folder is not specified as a source folder.我认为,您的源文件夹未指定为源文件夹。 To fix this, do the following:要解决此问题,请执行以下操作:

Go to modules(in the Project Structure menu)转到模块(在Project Structure菜单中)

Select your source folder(likely src )选择您的源文件夹(可能是src

Click on source folder above it.单击其上方的source folder

The source directory should be blue.源目录应该是蓝色的。

Save the changes(click ok to close it)保存更改(点击确定关闭)

It should work.它应该工作。

I'm not so sure about that (its kind of a bug that sometimes happens), but try putting your mouse on the "main" in the main function and then hit ctrl + Enter and choose run.我对此不太确定(有时会发生这种错误),但是尝试将鼠标放在主函数中的“main”上,然后按 ctrl + Enter 并选择运行。

hope this helps希望这可以帮助

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

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