Eclipse behaves inconsistently after system crash - java

I have an urgent and puzzling problem with Eclipse. My system crashed on itself this morning, and after I rebooted, I can run a program perfectly within Eclipse, by right-click on the Java file and choose 'Run as Java Application'. However, after I make the project into a .jar file, and execute that, the behavior of the program simply does not reflect what the code does.
I have checked that I am compiling the right project, and running the same code from the same project within Eclipse does not cause any problem. And btw, I am using a plug-in called fat jar to compile the .jar file, if that makes any difference. I have used the same plug-in numerous times before to compile the very same project, and never had any problem.
Does anyone know what might be causing this weird/inconsistent behavior of Eclipse? Do I need to re-install Eclipse and fat jar to fix this? Thanks.

My usual procedure for strange things like this is,
A) Clean and build again i.e. Project -> Clean
B) (not so eclipse related) Since I am usually using a build tool, do the same thing from the tool to ensure its eclipse.
C) If it gets really bad, I'll start a new eclipse workspace and try from there.
D) Iff I had just installed a new plugin before things went strange I'd think about reinstalling

It sounds extremely strange :)
But Eclipse can, and has, acted strange before. I have had problems in both Java, C++ and PHP development during the years that could only be fixed with a resinstall of Eclipse. You could probably fix it by digging around, but the time it takes to find and fix these types of strange problems in Eclipse is simply not worth it.
Good luck!

Please try to Reset Perspective first (Before reinstall eclipse)
Window->Reset Perspective.

Related

Why does any collection object not recognized? (VSCode) [duplicate]

Just starting working on an existing project at work and wanted to use Visual Studio Code as my IDE (I have used it for a recent Rails project and loved it, so wanted to try with Java).
However, whenever I try to open one of the projects I receive a ton of different errors including:
When importing java.io, java.util, or anything similar, the error:
"The import of java.io (or java.util) cannot be resolved"
Existing classes have an error:
"The implicit super constructor is undefined for default constructor. Must define explicit constructor"
Other random "cannot resolve to a type" errors.
All of these seem to stem from some sort of setting error I have with VS Code but can seem to find what it is. I have already uninstalled and reinstalled the RedHat plug-in that enables the Java language for VS Code.
I have tried setting the java_home setting in the extension to the direct location of the install but that didn't work. Tried uninstalling and reinstalling java and that also didn't work.
My operating specs are as follows:
OS: macOS Sierra
VS Code version 1.15.1
JDK version 1.8.0.144
Any idea on what may be causing this? Do you think it may be an error in how I have VS Code set up or if it's an error (or rather incompatibility) with how the existing project is set up?
I ran into a similar issue. The solution was to remove everything from VS Code's workspace storage directory, which was located at $HOME/Library/Application Support/Code/User/workspaceStorage/.
I found this solution here: https://github.com/redhat-developer/vscode-java/wiki/Troubleshooting#clean-the-workspace-directory
Update: This can now be done from within VS Code as of Language Support for Java(TM) by Red Hat Version 0.33.0. Open the command palette and type "java clean" (see official description in link).
As already mentioned previously, you require to clean the project, but that is a bit difficult thing because every folder is a Guid, and you do not know which one to clear, thus requiring you to delete everything. Starting with 0.33.0 version of the plugin you can automatically do that from within the IDE as well, use CTRL + Shift + P and type, java clean, and IDE will show you the suggestion tip for, Java: Clean the Java language server workspace. Upon selection, agree and restart the IDE. It will clean the language server workspace for you.
Another approach can be, the Maven tools within the IDE. If you have this plugin installed, you can use the side bar and utilize the Maven project helper options to perform actions like, clean, install, and package etc. For example, here is the project I am having and the options this shows,
That can be used, graphically, to manage your Maven-based projects. Also, this would work with the Java Extension Pack, not sure yet as to how it would behave with other extensions.
For me: CMD + Shift + P
Then type "Java: Clean Java language Server Workspace"
Note: This will reload/restart vscode as well.
Update:
This appears to not fix it anymore for me. In my case I am using a gradle project, and needed to set the rootProject.name in the settings.gradle to be the same as the folder name that the project is in.
I faced this issue after creating a whole Java project in one computer and then trying to run it on another computer.
After doing everything said in the other answers, what really made VS Code compile was to open each single project java file in VS Code and save it (a simple Ctrl + S). Maybe there is a simpler way of doing it, but that is what worked for me and I hope this helps anyone stuck in this issue.
Press ctrl+shift+p
then search 'java clean' and click 'java: clean java language server workspace' then click restart IDE.
I found another simple trick at least to get rid of "cannot be resolved to a type" errors which were coming from older workspaces and wrong project files I guess?. I just ran an empty main(), with the body commented out, while still keeping my local package / import commands at the start - no errors. After commenting in again, the project compiled without errors. Perhaps this refreshing effect might also help in this context?
I had to clean this folder to get it working on Windows
%APPDATA%\code\Local Storage

How do you use a Java project in your Android project in Eclipse?

I'm writing an Android application and there's some Java code in it that's somewhat sophisticated and therefore hard to verify the correctness of in the Android environment. I would like to run this code in a desktop environment where I have more tools with which to examine the output of this code while still using it in my Android application.
My attempted solution is to have three different projects in Eclipse. My Android project and two plain (non-Android) Java projects. One Java project has the sophisticated code that I want to use in Android and the other is a test program that verifies the correctness of the former project. The latter project has already been useful in debugging the former.
However, so far, my attempts to use the Java project in my Android project appears to work in the IDE but when I actually run the Android application, the NoClassDefFoundError exception is thrown whenever I try to access any of the classes. Obviously, that code is not being recompiled into the .dex file but why not?
I could go into detail about what I've done so far but I can't help but think that what I'm doing is a pretty standard and simple thing and there's a plain way of doing it, even though I can't find anyone doing quite what I'm trying. Can someone describe to me how this is done?
Luckily, I found the answer to my own question and I thought I'd share it here to help others in the same situation. It turned out to be very simple...
What I was already doing would have normally worked, which should have been a big clue to me since I have actually done this before, successfully. All you have to do is, under your Android project's Properties > Java Build Path > Projects, add the plain Java project to your "Required projects on the build path" and then under Properties > Java Build Path > Order and Export, check the checkbox of that same project in the "Build class path order and exported entries" list and everything should just work.
From within Eclipse, there's nothing else you need to do to get this setup to work. It's only when you're compiling from the command line that you need to build Java Jars and import them as libraries but I'm not doing that (yet).
Finally, this wasn't working for me because I just happened to be compiling my plain Java project under JDK 1.7 compliance, while my Android project was compiled under JDK 1.6. This is verified by the output on the Console pane, reporting "Dx bad class file magic (cafebabe) or version." This error message goes away when both projects are compiled under the same compliance level and, not coincidentally, the Android program runs properly.
Thank you to everyone who tried to help and I hope this answer is helpful to someone out there!
Would it not work if you made your other plain java project into an Android project and use it to monitor the output on the device?

Trouble with Java Programming Editors on Mac OS X

I've checked out Eclipse and jEDit and I'm having trouble with both.
With Eclipse I can't seem to open a java file and edit it then compile it. I always have to make a new project and then copt and paste my code. It's frustrating and a time waster.
With jEdit when I open files I'v worked on on other computers I get random characters. I also can't figure out how to compile.
None of this happens when I use JCreator on my PC. Will you guys lend me a hand?
Eclipse is project-based. It won't just compile a file on the fly, the whole IDE is based around having projects and then adding files to the projects and then compiling and running the projects. I agree that if you only have one file you're playing around with, this is a bit inconvenient, but that's the way it is. FYI: Your Eclipse should also have an "autobuild" feature which will compile your project as changes are made so you don't need to compile before a run (which is also usually automatic). For small projects on a powerful machine, the performance hit is usually negligible.
In Eclipse you don't need to "COMPILE". Every time you save your Java program, you also compile it.
Just RUN the program you are writing from the Run menu.
Never worked with jEdit, so I can't help with that but it looks like you are having encoding problems.
I have been working on Mac OS X with Eclipse and it was a very good experience. You definitely don't need to create a new project every time you want to change & compile something.
Hope it helps.

Eclipse is freezing itself before getting started

I've been trying to open Eclipse to start my work today, and it freezes everytime during load.
My Eclipse is Helios. Someone told me I should remove a file called .lock from .metadata folder, but still didn't work.
Does anyone have any idea of how do I "melt" this thing up?
ps: I opened it yesterday with no problems.
Have you already tried to start Eclipse with a -clean parameter? Sometimes this can resolve some issues..
I would suggest a (big) problem with a plugin in Eclipse.. because project plugins or runtimes will execute later.
Create a new workspace and repimport your projects from your old workspace. If you have a vcs, you can re-checkout them.
Start it with the -clean option.
It should take a bit longer (depends on your eclipse configuration and workspace, but if nothing is really broken, it will get it to work).
I believe something is wrong with your workspace. I typically remove current and create new one in such case. It usually takes up to 5 minutes (if I have to add 20 projects). In most cases it takes less.
I have experienced something similar when launching Eclipse after having to force close it for some reason.
If it always hangs when loading the SVN plugin — like in your screenshot — it is likely to be related to that. In this case I suggest the following:
back up your current workspace
launch Eclipse with the -data command line argument to specify a different workspace folder
if Eclipse starts up successfully, try to import your projects from the original workspace or even better from SVN

Eclipse cannot resolve enum in the same namespace?

I've run accorss a really weird issue, in eclipse I've got a codebase I've been working on for a couple of weeks and it's working fine. I did an svn update and all of a sudden one of my classes doesn't compile because it can't resolve an enum which is in the same namespace to a type.
I've checked the Java version and I'm running under Java 6 so enums should be supported.
Also it worked up till yesterday and now it doesn't.
Has anyone else seen this kind of behaviour? I've reloaded eclipse but beyond that I dont know where to start diagnosing it.
If it does say "Step cannot be resolved to a type", just try and clean the project (Project -> Clean). Eclipse gets confused sometimes, and a clean usually helps.
I had this recently. Turned out that someone had committed some jars that conflicted (had a previous build in) and put on the build path. Check recent commits to see if that's the problem, or to see what could have caused it.
However I would definitely do a build clean first within Eclipse, and see if ANT/Maven is affected (you do have such build scripts I assume).
Weird idea, but could it be that eclipse is trying to compile your class using a 1.4.2 compiler and isn't recognizing the enum?
I unloaded the project and reloaded it and it just works... No idea what the origianl issue was...

Categories