DonJayamanne / javaVSCode

Extension for java development on VSCode (deprecated)
https://marketplace.visualstudio.com/items?itemName=donjayamanne.javaDebugger
MIT License
43 stars 29 forks source link

Error: Could not find or load main class Test #54

Open skandhp opened 7 years ago

skandhp commented 7 years ago

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

faustinoaq commented 7 years ago

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

skandhp commented 7 years ago

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

skandhp commented 7 years ago

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 :/

faustinoaq commented 7 years ago

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

jugaltheshah commented 7 years ago

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.