Java Error: Could not find or load main class Test
16,320
Solution 1
I installed java 9 and openjdk 9.0.1 and it now works. No idea why Java 8u151 didn't work, but this does now.
Solution 2
Deleting .vscode/launch.json
worked for me.
https://github.com/Microsoft/vscode-java-debug/blob/master/Troubleshooting.md#reason-7
![Minimuscle](https://lh6.googleusercontent.com/--LraFBxdrXo/AAAAAAAAAAI/AAAAAAAAABY/HYaaNxs-09g/photo.jpg?sz=256)
Author by
Minimuscle
Updated on June 21, 2022Comments
-
Minimuscle about 2 years
Searched and can't find a reason why this doesn't work. I get this error when trying to run a simple program:
public class Test { public static void main( String[] args) { System.out.println("Hello"); } }
I have used the gear to automatically generate the launch.json file. I have also never really done anything before. I'm using VSCode with the redhat java and java debugger extensions. I have java 1.8.0 installed (+jdk)
launch.json code:
{ "version": "0.2.0", "configurations": [ { "type": "java", "name": "Debug (Launch)-Test", "request": "launch", "cwd": "${workspaceFolder}", "stopOnEntry": false, "mainClass": "Test", "args": "" }, { "type": "java", "name": "Debug (Attach)", "request": "attach", "hostName": "localhost", "port": 0 } ] }