Debugger for Java Build failed
I referred to here for settings etc. Getting Started with Java Programs Using Visual Studio Code
test.java
public class test {
public static void main(String[] args) {
for (int i = 0; i < 10; i++)
sayHello();
}
private static void sayHello() {
System.out.println("Hello World!");
}
}
It works at first When I reopen VS Code from the second time onward and execute it again, I encounter an event that I can not debug due to an error
this.
In the debug console
error:Main class test not found or could not be loaded
Come out.
"The java main class was not found or could not be loaded" 「VS code Debugger for Java Build failed」 When you google Many articles say that the path is wrong. But with such a simple source, it doesn't make sense to work the first time.
The problem is the VS Code workspace. From [File]-> [Open Folder] in VS Code If you specify the folder where test.java is located, the workspace will be one level higher for some reason. : sweat_smile :: sweat_smile :: sweat_smile ::
VScode refers to launch.json when debugging, but this is what is created automatically
{
//You can use IntelliSense to learn the available attributes.
//Hover and display the description of existing attributes.
//Check the following for more information: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Debug (Launch)",
"request": "launch",
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopOnEntry": false,
"mainClass": "",
"args": ""
},
{
"type": "java",
"name": "Debug (Launch)-test",
"request": "launch",
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopOnEntry": false,
"mainClass": "test",
"args": ""
},
{
"type": "java",
"name": "Debug (Attach)",
"request": "attach",
"hostName": "localhost",
"port": "<debug port of remote debuggee>"
}
]
}
"cwd": "${workspaceFolder}" I have this guy so I go to the workspace to look for test.java If you perform the operation of [File]-> [Open Folder], there is no such thing because the workspace is one level higher. : head_bandage: Therefore Error: Main class test was not found or could not be loaded Will be.
As a countermeasure, the location of the workspace should be the location where test.java is located. File-> Save Workspace As Save as a suitable name from here .code-workspace I can do it from the next time File-> Open Workspace OK if you open this file from
Why do you do [File]-> [Open Folder] I didn't know if the workspace would go up one level. There may be some settings: thinking:
Recommended Posts