Common Eclipse Problems

Here are some common Eclipse problems and some easy workarounds:

 

Normal-seeming things like Scanner, String, etc., are underlined in red as if they are errors!  Why do I suddenly have so many "errors" that should actually be OK?

You've got a build path problem.  In Eclipse, go to Project > Properties > Build Path > Click on the libraries tab.  From there, find the entry for JRE System Library.  Select it and click "remove."  Then, immediately click "Add Library" and, in the new window that pops up, select JRE System Library to add it back.  In that pop-up, click next and finish.  The errors should go away.

I'm getting lots of errors showing up with language features like enhanced for loops -- for(int x : myArray){ ... } -- or parameterized types -- declarations of objects or classes using something in angle brackets after the name of the class...like List<String> myList = new List<String>();  What gives?

When you have a project, it has to use a certain version of the Java compiler to turn your human-readable code into instructions that the Java Virtual Machine can understand.  That's compilation.  The compiler has changed over time as the language has been updated.  You're probably set to an older version of the compiler that came out before those language features -- like enhanced for loops and parameterized types -- came out.  

The solution is for you to update the version of the compiler you're using.  I suggest that you just bring it up to Java 8.  Follow the steps above to get your Build Path properly set up using Java version 8 (you should see "1.8" in the option you select.)  

Now let's update the compiler version.  Go to Project > Properties > Compiler > set your compiler version to 1.8.  Right now, it's probably at something lower, like 1.4 or 1.5.

All my projects disappeared from my workspace when I opened up Eclipse today!

Q1: Are your files totally gone?

A1: Navigate to your workspace in the Mac Finder or in the Windows Explorer.  Open it up to see if your files are actually gone or not.  

  • If they aren't there, you're out of luck.  Hope you backed up your work.  
  • If they ARE there, you're in luck.  
    1) Copy your entire workspace to another folder somewhere on your flash drive.  Keep track of where this is.  
    2) Now go to Eclipse and do File > Import > General > Existing Projects into Workspace > Browse to the copy of your workspace you just made.  
    2a) If it DOES allow you to import the projects, make SURE that the "Copy projects into workspace" box is checked.
    2b) If it does NOT allow you to import the projects because it says that they already exist in the workspace...navigate again to your workspace in Finder/Explorer and CONFIRM that there's nothing there.  If there IS something there, delete it all.  (Remember, you backed it up somewhere else.)  Then try importing again after having deleted the old stuff

My project icons in Eclipse are not showing up properly.  I can't expand them to look inside the packages.  They just look like folders.

Are you sure you're looking at the Package Explorer and not the Navigator?  Go to Window > Show View > Project Explorer

My console disappeared

Go to Window > Show View > and select the console

I'm trying to run my main method -- which is properly formed -- but I'm getting an error: Could not find the main class: net.mrpaul.ads.csid.psXX.MyClassName

Your project's .metadata file is corrupted.  

FIX 1: Right-click the package name and click refresh.  Then right click the class name in the package explorer and select "Run as" > "Java Application."

FIX 2: Go into your workspace using Finder/Explorer and copy the project in question's entire folder to somewhere else as a backup.  Remember where you paste it.

Then go into Eclipse and delete the entire project from your workspace.  It will ask you if you want to also delete the files from disk.  Say yes.

Then File > Import > General > Existing Projects into workspace to bring the back-up project file into your Eclipse Workspace.  Make sure you have selected "copy project files into workspace."