How to solve java issue - could not load main class - Visual Studio Code

August 14, 2019

Assuming you have a java project and is using Visual Studio Code as IDE. All of your programs were running perfectly fine. Suddenly, you ran a main class and you encountered with this error:

Could not find or load main class

And, there is no compilation errors. No error in problems tab in IDE. Only warnings may exists.

Solution

This solution assumes your java project/program is having no compilation error.

This issue happens most of the time when you have moved/renamed multiple files or folders in your project. The issue exists with Visual Studio Code as its registry becomes out of sync with these bulk files rename operation.

The solution is to remove the workspace directory. You may find the locations:

    Windows : %APPDATA%\Code\User\workspaceStorage\
    MacOS : $HOME/Library/Application Support/Code/User/workspaceStorage/
    Linux : $HOME/.config/Code/User/workspaceStorage/

You may need to restart your Visual Studio Code. And, try to run now. It should work.


Similar Posts

Latest Posts