Eclipse: Could not find or load main class classnotfoundexception (with fix) - java

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.

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.

Related

Eclipse Error: Overlaps the location of other project

I am trying to create a new java project in my workspace. But i am getting the following Error:
"Overlaps the location of other project"
My current projects in:
Documents/workspace/Folder/{projects(About 10 Projects)}
If i create a new project from Eclipse, the new projects are coming under:
Documents/workspace/{New Project}
I have tried to the following steps to resolve this mentioned in other posts in stackoverflow.com:
Eclipse: Error ".. overlaps the location of another project.." when trying to create new project
But i am not able to solve this. Can anyone help please?
Ok, I fought this issue for a day and feel quite humble when I finally read all the post and figured out a good solution. This should be added to an Eclipse ten commandments... Thou shalt separate your workspace from your code and never the two shall meet. In that create the folder structure something like this:
C:\workspace\training\
C:\training\maven102-section1-initial-master\...
When you open Eclipse, point your Work space to the "c:\workspace\training" area. And for all your code, keep it in the "c:\training\maven102..." area.
My issue was having EVERYTHING ALL in the same folder, like a big old hoarder... and that does not work out either. Enjoy!

Issue Creating New Project Eclipse

I am using eclipse for the first time in a few weeks and when I try to create a new project it is being marked as a test and gives me an error when I create a main method.
I have been using eclipse for a while and this error happened once previously. I solved it by messing around with a bunch of settings in properties/preferences and reinstalling eclipse but I would really appreciate help finding an easier way to fix this.
Here is the main method that I have. I am not really concerned about the error with the main method, more so with why the projects have [test] when I create them.
Not sure if this helps, but when I go to create a project this is the first instance of the [test]

Android : The Missing R

I have seen alot of cases of "R cannot be resolved to a variable". Though my case is odd.
It was working perfectly about 15 minutes ago and within that frame, R has now vanished and cleaning the project won't cut it.
I have also ensured that all of my SDK parts are up to date before and after the incident. And the problem still occurs.
Can anyone figure out a solution as to why it would disappear just like that? Even though the SDK was up to date before R vanished?
And another question. Why does this R file cause so much trouble? (I am using Eclipse btw)
This can certainly be a nuisance.
Make sure any R. imports haven't sneaked their way in. Your imports should be bereft of any 'R.'
If you have changed your package name recently, ensure that AndroidManifest.xml is still pointing to the correct package. Using eclipse to refactor does not guarantee the manifest will update.
A side note, if you have errors in your xml files (layouts etc) this will cause a Resource error. Not all errors will be caught by eclipse, so you have to go through those files with a fine comb.
Sometimes simply cleaning, closing and restarting eclipse can help.
Check if you've recently added some music or pictures (any type of resource generally) to your res folder structure. Name of resource must be in lowercase completely, must not start with number...
Also look at the output in the eclipse console. It sometimes show error messages if it can't generate R.java

NO java.lang.NoClassDefFoundError error in Eclipse

I have a project in eclipse which was working fine untile a few minutes ago. I added a JDBC driver ad tried to run it, now even previous runnable file are giving me
Exception in thread "main" java.lang.NoClassDefFoundError: sample
Does anyone have any idea why it is happening does it have anything to do with the jar?
I have even removed the jar.
Try following, one by one
If you are using libraries, check whether everything is included to the project properly.
Rebuild the project
'worked few minutes ago' means it used to work. Did you add any new code? Then the error is there, check whether those codes call other classes, and whether they are available
Restart IDE
Once I used the following to solve the same issue
http://javarevisited.blogspot.com/2011/06/noclassdeffounderror-exception-in.html
If all above failed, that may be due to crash in JVM. I have experienced that as well.

Error: Unable to fnd class R.java No such file or dir

I keep getting this when trying to start a new project
ERROR: Unable to open class file C:\Users\Levi\Desktop\Android\workspace\Droid1\gen\com\androidbook\droid1\R.java: No such file or directory
I tried changing preferences to alter build path to project, but it still wouldnt work,,,
Is subfolder on desktop a bad place to install Eclipse?
Clean works sometimes and should be tried. I also find that blowing away the gen directory and refreshing will cause it be to rebuilt. Try that as well.
However, sometimes even that doesn't work and I've been forced to remove the project from Eclipse and then re-import it. This, unfortunately, works for me every time if the above has not.
Good luck.
Im also getting that error, running a Project->Clean in Eclipse helps for me.
Project->Clean should certainly fix this (unless your resources won't compile for some seperate reason).
I remember that the first time I ran Eclipse (in mid 2009, can't remember if it was Galileo or Ganymede or whatever) on Windows Vista, it presented several problems that were eventually traced to Eclipse itself being in a directory whose path contained a space...
Usually, the above tips (refresh, clean) work for me. But lately I had a very persistant instance of this error, which was caused by something else:
One of the layout .xml files in res/layout contained a reference to a custom view (org.company.project1.MyView). However, I had changed the package path (org.company.project2.MyView), so the reference had become invalid.
Thus, if everything fails try browsing your layout .xml files for invalid custom element definitions.
Cheers
after spending hours trying to ultimatly discover the issue behind the Class Issue not being found, resolved,or directory not there issue....
sometimes yes the issue is due to a bad binary or xml... as sometime a clean will do the trick or a xml edit will solve the day.. when all else fails.... this may do it..
"create a new workspace"
go into the workspace.... and then
Switch to your old workspace... in the newly formed workspace...
this was my silver bullet. so frustrating to not have a solid answer.
using Version: Helios Service Release 2
Build id: 20110218-0911

Categories