~/vscode/visual-studio-code-java-main-class-not-found.md

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

1 min readAugust 14, 2019by Gorav Singal#vscode
// 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.

$ subscribe --weekly

One deep dive a week, in your inbox

System design, AI engineering, trading systems and interview prep. Tested code, real numbers. Free, and you can unsubscribe any time.

or read it on gyanbyte.substack.com

Share

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

Claude Code Skills — Build a Better Engineering Workflow

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

Building an AI Voicebot for Visitor Check-In — A Practical Guide to Handling the Messy Parts

Building an AI Voicebot for Visitor Check-In — A Practical Guide to Handling the Messy Parts

Every office lobby has the same problem: a visitor walks in, nobody’s at the…

Latest Posts

How to Stay Valuable as a Software Engineer in the AI Era: A Practical Playbook

How to Stay Valuable as a Software Engineer in the AI Era: A Practical Playbook

In the previous article I argued that AI is not killing software engineering…

How to Review AI-Generated Code: A Checklist for Catching What the Model Missed

How to Review AI-Generated Code: A Checklist for Catching What the Model Missed

A few months back I approved a PR that was almost entirely AI-generated. It…

How to Debug AI-Generated Code: Understand First, Fix Last

How to Debug AI-Generated Code: Understand First, Fix Last

In the last article I wrote about reviewing AI code before it goes in. This one…

The Future of Software Engineering: What AI Changes, What Stays, and Where the Jobs Go

The Future of Software Engineering: What AI Changes, What Stays, and Where the Jobs Go

Every few weeks somebody sends me a scary headline — “AI will replace all…

The Transactional Outbox Pattern: Never Lose an Event Again

The Transactional Outbox Pattern: Never Lose an Event Again

This is one of those patterns that looks like nothing until you get burnt once…

Event Sourcing, Explained: Store What Happened, Not Just the Final State

Event Sourcing, Explained: Store What Happened, Not Just the Final State

Here is a question I like to ask in interviews: your bank account shows a…