0

I am run my java code in IntelliJ it is showing this error:

Error: Could not find or load main class CWA_01_INTRO Caused by: java.lang.ClassNotFoundException: CWA_01_INTRO

whereas the same code is running in vs code, I am looking for your affirmative help.

I have asked some chatgpt , pieces copilot but not getting a summarize solution, rather than list of causes.
Here is my code

import java.util.*;
public class CWA_01_INTRO {

    public static void main(String[] args) {
        Scanner as = new Scanner(System.in);
        System.out.println("Hello World ");
       
        as.close();
    }
}
2
  • 1
    Post entire error message. Don’t make us guess! Commented Oct 11, 2024 at 14:01
  • 1
    Post details as edits to your Question, not as Comments. Commented Oct 11, 2024 at 18:03

1 Answer 1

2

Mark src as Sources Root: Right-click on the src folder, select Mark Directory as → Sources Root.

Check Run Configuration: Go to the run configuration dropdown, select Edit Configurations, and ensure Main class is set to CWA_01_INTRO.

Rebuild the Project: Go to Build → Rebuild Project.

Check Output Path: In File → Project Structure, verify the output path is correct.

Invalidate Caches: Go to File → Invalidate Caches / Restart, and choose Invalidate and Restart.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for your answer but in project structure I made my folder as source file then program is running just to confirm I have to make every folder as source file or make parent folder as source file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.