java - IntelliJ IDEA is not recognizing my java files as runnable and instead wants to run the class files. Any ideas of how to fix?
问题描述
Anytime I try to run a java file by clicking run, it instead tries to run the class file and thus gives a no main method error.
When I try to right click on a java file and run that, it doesn't recogize it as a file that is runable.
I am still able to run programs from the command prompt but I would prefer to be able to run them in IntelliJ.
This occurred after trying to create a Class path when using JSon Libraries.
Edit:
Normally it shows java files with this icon:
But instead it's showing this icon for java files:
I think the change in icon might have something to do with it.
Edit 2: the exact error I get is "C:\Program Files (x86)\Java\jdk1.8.0_181\bin\java.exe"...bunch of other program file locations
Error: Could not find or load main class sample.Main
Process finished with exit code 1
解决方案
我遇到了同样的问题,发现我的 src 没有标记为 Sources Root。要改变这一点:
- 鼠标右键单击您的 src
- 导航到“将目录标记为”
- 选择“Sources Root” 它现在可以正确识别您的文件,并且您的主类将能够再次运行
推荐阅读
- surface - 如何使用 OPENCASCADE 使用截面制作实体
- ios - 如何使用 Button Tap 在 SwiftUI 中移动视图或向 NavigationLink 添加操作?
- amazon-web-services - 关于 AWS Lambda 事件源状态的 Cloudwatch 警报
- sql - 我从一个函数返回一个表,然后在另一个查询中使用它
- ionic-framework - 如何创建通知列表 Ionic
- python - 如何在 Python 中删除 JSON 文件中的空格和 \n
- javascript - DIV 不使用 getElementsByClassName() 移动
- python - pool.imap_unordered 是否需要内存中的所有输入?
- excel - 简单的 VBA 代码使用相同的输入给出不同的结果
- linker - 我试图通过 MSYS2 为 Windows 构建 Libxls 静态库和动态库,但它不起作用