I have had this problem for years and years now where Eclipse would sometimes, seemingly for no reason, throw this error:
Error: Could not find or load main class [main-class] Caused by: java.lang.ClassNotFoundException: [main-class]
This error fires despite the class being in the file system and having previously worked with no flaws. Project clean does not fix it, and the filepath is completely valid. Consequent Google Searches usually turn up recommending that it's one of those two problems, or that you have to completely delete the project, or create a new workspace - so on.
I'm not sure what the exact cause of this problem is, and I haven't ever really been able to find one neither. However I had found a relatively simple fix for correcting it.
CodePudding user response:
To fix this problem, what I've learned is that for some reason it tends to be Run Configuration itself. What you can do is:
- Click "Run" in the toolbar
- Click "Debug Configurations"
- Create a new Run Configuration (However, don't just copy and paste the old one - for some reason this doesn't always fix the problem for me)
- Set it up appropriately for the class, you can however copy the parameters from the old
- Save and use that as the new run configuration for your program
This has generally fixed the problem for me most times. Hopefully someday Eclipse will have this properly fixed.
My current Eclipse version is 2021-12 (4.22.0)
I don't know if I did this self-answered question thing correctly, but for those of you who are banging your heads against your keyboard on Google right now trying to fix this, I hope this helps.