vscode|August 14, 2019|1 min read

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

TL;DR

Clean the Java workspace in VS Code to fix the 'could not load main class' error that occurs despite no compilation errors being present.

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

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.

Related Posts

VS-Code - How to Debug and pass Command Line Arguments via Launch Config

VS-Code - How to Debug and pass Command Line Arguments via Launch Config

Introduction In this post, I will take example for Python project. And how we…

VS-Code - How to put vscode executable in system path and how to open source code directly in vscode

VS-Code - How to put vscode executable in system path and how to open source code directly in vscode

Introduction VS code is an excellent free IDE for maany types of programming…

Microsoft Visual Studio Code - Must-have extensions for Developers

Microsoft Visual Studio Code - Must-have extensions for Developers

Visual Studio Code is one of the awesome developer tools by Microsoft. Let’s…

Visual Studio Code - How to associate file extension to a known programming language

Visual Studio Code - How to associate file extension to a known programming language

Problem Statement I have a drupal module, where there is a file of extension…

Claude Code Skills — Build a Better Engineering Workflow with AI-Powered Code Reviews, Security Scans, and More

Claude Code Skills — Build a Better Engineering Workflow with AI-Powered Code Reviews, Security Scans, and More

Most developers use Claude Code like a search engine — ask a question, get an…

Staff Engineer Study Plan for MAANG Interviews — The Complete 12-Week Roadmap

Staff Engineer Study Plan for MAANG Interviews — The Complete 12-Week Roadmap

If you’re a Senior Engineer (L5) preparing for Staff (L6+) roles at MAANG…

Latest Posts

Claude Code Skills — Build a Better Engineering Workflow with AI-Powered Code Reviews, Security Scans, and More

Claude Code Skills — Build a Better Engineering Workflow with AI-Powered Code Reviews, Security Scans, and More

Most developers use Claude Code like a search engine — ask a question, get an…

Server Security Best Practices — Complete Hardening Guide for Production Systems

Server Security Best Practices — Complete Hardening Guide for Production Systems

Every breach post-mortem tells the same story: an unpatched service, a…

Staff Engineer Study Plan for MAANG Interviews — The Complete 12-Week Roadmap

Staff Engineer Study Plan for MAANG Interviews — The Complete 12-Week Roadmap

If you’re a Senior Engineer (L5) preparing for Staff (L6+) roles at MAANG…

XSS and CSRF Explained — The Complete Guide with Real Attack Examples and Defenses

XSS and CSRF Explained — The Complete Guide with Real Attack Examples and Defenses

XSS and CSRF have been in the OWASP Top 10 for over a decade. They’re among the…

OWASP Top 10 (2021) — Every Vulnerability Explained with Code

OWASP Top 10 (2021) — Every Vulnerability Explained with Code

The OWASP Top 10 is the industry standard for web application security risks. If…

HTTP Cookies Security — Everything Developers Get Wrong

HTTP Cookies Security — Everything Developers Get Wrong

Cookies are the single most important mechanism for web authentication. Every…