javaVSCode icon indicating copy to clipboard operation
javaVSCode copied to clipboard

Error: Could not find or load main class Test

Open skandhp opened this issue 7 years ago • 5 comments

I'm trying to set up VSCode for java. I've set up the launch and build task files as instructed in the readme page. But I'm getting "Error: Could not find or load main class Test". My JAVA_HOME is set up correctly and I've given the fully qualified class name, but it still won't work. Another problem is that the compiled .class file is being generated in the same directory as the .java file (as opposed to /bin directory). I tried modifying the task file to use the "javac -d" option but it didn't work. Can any one help me out?

Test.zip

skandhp avatar Jul 09 '17 16:07 skandhp

Can you take some screenshots? please :sweat_smile: so we can understand you better

faustinoaq avatar Jul 09 '17 17:07 faustinoaq

hey! Sorry about that. Here are the screenshots! image image image

skandhp avatar Jul 09 '17 18:07 skandhp

I noticed something else while taking the screenshots! Java-debugger no longer seems to be working. Alt+R produces no output now (not even the previous error message). I'm new to VSCode, I'm pretty sure I'm missing something :/

skandhp avatar Jul 09 '17 18:07 skandhp

You have some configuration like classpath that isn't avaliable yet, You need to see the issue https://github.com/DonJayamanne/javaVSCode/issues/19 to get some help.

You also can clone this repo in your extension directory and do npm install to have the latest features.

I attached a screenshot with your example working:

screenshot_20170709_142521

faustinoaq avatar Jul 09 '17 19:07 faustinoaq

Not sure if you ever resolved this, but my default launch.json file came with the classpath directive as well and I got this error too. I noticed my .class files were building in the folder above my .java files. E.g.: /home/user/Projects/ProjectName/Sub Folder/[file1.java, file2.java, etc] /home/user/Projects/ProjectName/[file1.class, file2.class, etc]

I was able to fix the error by adding a line to the classpath referencing the dir above current dir: "classpath": [ "../", ".", "${fileDirname}" ]

From your screenshots, it looks like the .class files are building right next to the .java files, but you don't have a reference to the current dir in your classpath. So add a simple "." to your classpath (like line 2 in my classpath above) and see if that works.

jugaltheshah avatar Aug 07 '17 03:08 jugaltheshah