4

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
    }
]
}
Minimuscle
  • 117
  • 1
  • 1
  • 8
  • Hi Josh, looks like this might be issue with VSCode java extensions, my suggestion is to use eclipse which is designed specifically for Java Development. –  Dec 22 '17 at 03:52
  • Duplicate of https://stackoverflow.com/questions/18093928/what-does-could-not-find-or-load-main-class-mean/18093929#18093929 – Stephen C Dec 22 '17 at 05:07

5 Answers5

8

Deleting .vscode/launch.json worked for me.

https://github.com/Microsoft/vscode-java-debug/blob/master/Troubleshooting.md#reason-7

Mikeumus
  • 3,570
  • 9
  • 40
  • 65
1

VS code offers the option to "Fix". It cleans and rebuilds the project. This worked before trying any of the other solutions.

actopozipc
  • 93
  • 12
0

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.

Minimuscle
  • 117
  • 1
  • 1
  • 8
  • It is unlikely that you have addressed the root cause of your problem. I suggest you read this: https://stackoverflow.com/questions/18093928/what-does-could-not-find-or-load-main-class-mean/18093929#18093929 – Stephen C Dec 22 '17 at 05:06
  • @StephenC I'm thinking it is a problem with openjdk 1.8.0 not working with the VSCode extensions, not java itself. As I was not working within the terminal. openjdk 1.9.0 seemed to fix it – Minimuscle Dec 23 '17 at 09:32
  • What evidence do you have for this *that someone else can verify*? – Stephen C Dec 23 '17 at 12:30
  • You see, I **don't** think this is the real solution to your problem. Unless you can provide us with an MVC that *other* people can use to reproduce the problem ... and test your solution ... there is room for doubt that the problem is real and the solution (upgrading to Java 9) is necessary. – Stephen C Dec 23 '17 at 12:38
0

I faced the same problem.While debugging in VS code 1.35.1 it showed the errorCould not find or load main class in the Debug console.So I tried uninstalling and then reinstalling the latest version of VS code and now it is working fine.

Animesh Jaiswal
  • 331
  • 3
  • 7
0

I had the same issue. I believe it might have been triggered by opening Eclipse for the first time since migrating to VSCode. Regardless, the solution that worked for me was:

  1. Make any change to your pom.xml (add a space somewhere outside of all brackets)
  2. Save pom.xml
  3. Delete the added space (steps 3/4 only required if you're OCD)
  4. Save pom.xml again
  5. A prompt will appear: "A Build file was modified. Do you want to synchronize the Java classpath/configuration?" Select "Yes."

Note: I use Maven. I would think the same steps would work for build.gradle if using Gradle.

Dhaval Solanki
  • 4,589
  • 1
  • 23
  • 39
Mitch
  • 13
  • 3