I took the following code from a tutorial:
import javax.swing.*;
import java.util.Date;
public class SwingGUI {
public static void main( String[] args
The problem is not in code.
It is due to JRE misconfiguration for project. It may be due to difference between the project's JRE and workspace's Jre.
It may be solved by Updating Eclipse or Jre...
But from my side, I recommend you to do so..
Goto Window-->Preferences-->Java-->Installed JREs--->Execution Environments-->Select Project's JRE and tick the perfect matching installed JRE.
If you have not a matching JRE download and add it in Installed JREs using Add Button.
At last, RESTART your Eclipse IDE. This worked fine for me...
If it does not work, UPDATE Eclipse..
There must be an installed (and selected) JDK in Eclipse:
Window > Preferences > Java > Installed JREs
The project must be configured to use that JDK:
Project > Properties > Java Build Path > Libraries
there should be an entry like "JRE System Library [JDK7]" in the list. If not press:
Add Library... > JRE System Library
The project should have been created as a "Java Project":
Project > Properties > Builders
should include "Java Builder"
SoCodeIt IDE Dr
Obviously the problem did not lie in the code, because it worked for everyone else. So I decided do remove and re-install java and eclipse, et voilà! Now it works. Thank you all for your feedback.
I faced the same issue and found that my project was using the Java 8 libraries.
I installed the Java 7 library, added the same to the project properties by referencing the library from the installed C:\Program Files\Java
folder and the error was gone.
Looks like, the new Java 8 version may a different way to resolve the swing component.
I was also facing the same problem in eclipse IDE but after changing the jar file to jre7(Right-click project>>Buildpath>>Configure build path>> AddLibrary>>Jre System Library) the error has resolved, i don't know how it happens can some one explain it.
Updating the execution environment under system library to JavaSE-1.7 or JavaSE-1.8 in eclipse should solve the problem. To update the step below can be followed:
> Right-click on the project
> Select properties
> Java build path
> Library > Add Library > Add JRE SYSTEM Library
> Execution Environment
> Select JavaSE-1.7 or JavaSE-1.8
> Finish