编程笔记

lifelong learning & practice makes perfect

vscode java debug,Could not find or load main class x

环境

vscode + 插件 (Extension Pack for Java,多个插件集合)

issues

Program Error: Could not find or load main class x

报错,”Program Error: Could not find or load main class x”

可能是launch.josn中的主类名称错误或者文件不再classpath
主要检测以下几项:

  • Check whether the class name specified in mainClass exists and is in the right form.
  • Run VS Code command “Java: List all Java source paths” to show all source paths recognized by the workspace.
  • Check the Java file you are running is under any source path? If not, go to File Explorer, right click the folder containing your Java file, and run the menu “Add Folder to Java Source Path” to mark the containing folder as a Java source root.
  • Run VS Code command “Java: Force Java compilation” to rebuild your workspace.
  • If the problem persists, it’s probably because the language server doesn’t load your project correctly. Please reference the language server troubleshooting paragraph for more troubleshooting info.

首先确认下java源文件是否在”Java source paths”,不在可以右击所在目录选择”Add Folder to Java Source Path”添加
然后确认源文件文件名称是否与主类名称一致.
点击Run或Debug Vscode会自动在.vscode/launch.json中添加配置,如图

vscode,java,debug
Add Folder to Java Source Path

参考:

欢迎关注我的其它发布渠道