Eclipse reorganizing packages and classes automatically? - java

I am having a strange situation where Eclipse is doing this. Here is a screenshot:
Here is the screenshot of my Github repo where updates are pushed:
Thus, I think 'src/noobchain' is the folder/package thing I want to keep and I want to delete the lower 'src' folder/package thing because it is a duplicate. It wasn't like this before, I just had the 'src/noobchain' but then Eclipse did something on its own (I know this because I checked the Edit to undo and it was greyed out).
Now when I try to delete one or the other, they both get deleted.
So I came up with possible solutions in my head now which is to do a 'git pull' to my local after closing Eclipse and then restarting Eclipse. But I'm wondering if someone else experienced this odd behavior by Eclipse Photon on Ubuntu 18.04.

I did as Goibniu suggested above by right clicking on src and then build path->use as source folder and I ended up with:
It looks weird with two sets of the classes but I can run it so no complaints I guess.
When I try to delete the src it tells me it contains a Java source folder, it will delete the source folder as well. Thus, I guess I have to leave it alone. Not a perfect answer but it works. If anyone has a better solution, please post.

Related

Eclipse Mars: code is gone

Please, help! I opened Eclipse Mars to continue coding and my code is gone! I don't know what could have caused this but it's all gone. Does anyone have any idea what can I do?
Note: I tried to right-click the java file->Replace With->Previous from local history. But a message says "No local history available for selected resource". Is there any other way?
Thank you in advance!
The first step in debugging this problem is to find out if the code is still exists without using Eclipse. Several possibilities come to mind:
The code is still where you expect, the files exist and the content is OK.
The code is still where you expect, the files exist, but the files are empty.
The workspace directory does not exist any more.
You need to use a file explorer program to find the files and check they are not empty. Try opening them with Notepad++ or similar. If you are lucky, option 1 will be the answer, and Eclipse has got confused. Just use File/Switch Workspace to set the workspace to the directory and all should come right.
Options 2 & 3 indicate you have lost data. There is probably little chance of recovery. Revert to your backups (you do have them?). Otherwise learn a lesson and set up a GIT or SVN server (or subscribe to a cloud service). I just use a very old laptop running Ubuntu with SVN server installed.
As a side issue, Eclipse does not randomly delete or empty files. There are millions of developers world-wide using Eclipse, and if it existed, such behavior would be all over the internet.
I had the same problem and found my file with a strange name in local history with this path:
".metadata/.plugins/org.eclipse.core.resources/.history/"
It was not the last version but better than nothing :)

Eclipse forgot all my projects?

That topic might have sounded a little silly, so forgive that, but here's what's happening:
I have several folder in my Package Explorer that contain several projects I've been working on.
The problem is that Eclipse seems to not find my projects within my folder.
Those folder-like icons are suppose to be double-clickable to reveal my projects...
But after I closed up last time, they won't show up again.
None of them!
And they're all there. In the Workspace I've always used. All the files, all the folders, all the everything.
Why can't Eclipse find them?
I've tried creating a new Workspace, as well as importing the old projects over again, but then I got the error that these projects already exist.
I've restarted Eclipse, restarted my computer and anything else I can think of restarting.
The biggest issue I have is that now I can't access any of my work, and thus can't keep working on it!
Could anyone be kind enough to take a stab at how I should go about fixing this?
Please, be gentle. I'm a little green to all this.
You can go into arcives in the top-left corner and click on projects to see if it's the correct project folder.
Another thing you can do is to check if the project-files are still in the folder where you have your workspace. If they are there it can help to create a "new" project with the same name and all the files will automaticlly be in the project again. :)

Eclipse won't generate import statements, stopped showing Quick Fix suggestions

My Eclipse installation suddenly stopped showing import suggestions. If I type a class name that isn't in the current package, autocomplete works fine and shows the class, but after picking from the drop-down, the class name is highlighted as an error with the message "MyClass cannot be resolved to a variable". This error shows no Quick Fix suggestions. However, if I manually add the relevant import statement at the top of the file, the code compiles and runs fine.
I've checked my build path and everything appears to be in order -- and like I said, the code runs when I hand-jam the import statement -- but losing automatic importing is really slowing me down. Any idea what could have gone wrong? It worked fine last week!
ETA: Another note, if it helps: F3 still opens the class declaration, so Eclipse clearly knows what I "mean", even without the import statement.
Also also: Things that have not helped:
Clean all projects
Restarting Eclipse
Restart computer
Delete .metadata from workspace, re-import project
Start new Java project, re-link source folder, re-add dependencies (not using Maven, but that's not my choice)
Thanks for all the help, everybody, but this turns out to have been a case of a broken Eclipse install.
I still haven't figured out exactly how or what was broken, but I tried to make a new project with a single "Hello World" class. The New Class wizard errored out with "Creation of element failed" in the class org.eclipse.wst.jsdt.internal.core.dom.rewrite.ImportRewriteAnalyzer. Once I hit "internal errors" in Eclipse, I gave up and installed a fresh Eclipse from a new download.
With a new Eclipse, I got my Quick Fix suggestions back, as well as automatic imports. I guess in future I'll try reinstalling Eclipse before I go looking for solutions to obscure errors like this :-/
These kind of situations can occur if your workspace went into a bad state or eclipse was unable to properly save state during last exit of workspace.
Try Project > Clean and clean all projects and rebuild all. See if this helps.
Clean all your projects. Then update Eclipse. Then restart of Eclipse. Then restart your development PC.
This happens to me sometimes too, I follow these steps and the problem always goes away.
If none of the other answers works, one brute force suggestion which sometimes resolves weird issues like this would be:
Close your Eclipse
Delete the .metadata folder inside your Workspace folder
Restart Eclipse
Note: This way you're going to lose all your workspace configuration. I advise you to backup it first in case it doesn't works.

Intellij IDEA doesn't detect changes

Yesterday I refactored my project and I changed layout of my packages (I moved some packages into another packages, created new packages etc). But now, when I try to run JUnit test I get NoSuchMethodError on methods which name is changed after refactoring. Also, when I change other code in methods, IDEA still running old code.. I tried to run "Invalidate caches" in File menu, also I tried to reboot computer - no result. Where can be problem?
EDIT: Yesterday after moving packages IDEA doesn't correctly change package declarations in .java files, so I changed them by hand
VCS -> Refresh File Status solved this for me, when Intellij suddenly stopped noticing changes.
What I did in order to solve the issue was to "invalidate and Restart":
File -> invalidate and Restart
SOLUTION:
Error magically gone after 2 things:
I imported this project into eclipse and run JUNit test from eclipse. Then I returned to IDEA and deleted all Eclipse specific files.
I synchronized my project (File->Synchronize).
I don't know what actually was the solution of problem, but for suggestions I accept #SeanLandsman's answer
I have two suggestions you could try here
Edit your test configuration(s) and ensure that they're pointing to what you expect them to. I've sometimes seen a refactoring not being picked up in the run configuration and I've had to manually change it
Less likely to work, but try to synchronize your project: File->Synchronize. Do this at the highest level of your project
With regards to your edit - I've not seen this myself. Whenever I've renamed or moved files (including packages) these changes have been correctly applied to all applicable files. Are you refactoring with Refactor>Move / Refactor->Copy ?
Answer to an old question, but:
If you're using a Run Configuration, make sure in the "Before Launch" section of the "Run/Debug Configurations" dialog, you have added "Build". It seems to get removed from this dialog sometimes, even if you have it added in the default settings.
Deleting the entire content of the classes dir worked for me
Another root-cause can be:
If you are using Lombok, try to deinstall/reinstall the Intellij Lombok Plugin.
That solved such a strange behaviour in my case!
Try deleting .class file of class where nosuchmethod error is throwing, and recompile.
This worked for me.
In IntelliJ IDEA,
Right click on the project.
Select Git -> Show History.
Opens "Version Control"
Then you can navigate to Local Changes Tab.
Found this posting from IntelliJ and Maven not finding POM changes. Had to Reload All Maven projects to fix it. Maven panel, upper left corner circle of arrows button.

R.java not generated or updating. Deleting itself for no known reason. HELP every solution tried,

I've checked every site I can find for the last two days and read more that I could imagine it would take to fix this.
I had an app half made and then I couldn't get java to see a layout I had made. I hit clean like I had on many other things. Then R.java disappeared.
I deleted the layout just to be sure it wasn't the cause. R.java did not come back.
I then decided to rebuild from the previous project. About a quarter of the way through the same thing happens.
Now, half the time I start a new project R.java isn't there to begin with. And when it is there it doesn't update at all.
I have made sure to update to the newest software. I've tried "Build Project" I've tried restarting eclipse.
I have tried saving my R.java file and then when it auto deletes I replace it with the recent save. I get aapt.exe has experienced a problem and needs to close" which also happens when I try to clean the old projects to fix them.
This is wrecking my coding.
I often have problems with the R file as well. Here are some things you can try:
Delete R.java and see if it regenerates (make sure Auto build is turn on)
Turn off auto build and manually compile the project
Go to your hidden .android folder and delete debug_keystore, then restart Eclipse and rebuild. May need to restart the computer as well.
Completely uninstall and reinstall Eclipse
Then there's the other suggested answers... check your XML files for errors, make sure your classes import the correct R file instead of android.R, etc.
Do you get any specific error messages in the console?
This happens for ALL your projects?
On eclipse package explorer menu (left menu that your projects are listed) right click, select android tools,select fix project properties,
if it works, let everyone know so other people can benefit.
Check if you accidentally imported android.R, this can cause problems also. See answer from Lars here: Missing R.java file even though project cleaned

Categories