java swing component cannot be resolved

前端 未结 9 1988
灰色年华
灰色年华 2020-12-11 16:43

I took the following code from a tutorial:

import javax.swing.*;
import java.util.Date;

public class SwingGUI {

    public static void main( String[] args          


        
相关标签:
9条回答
  • 2020-12-11 16:48

    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..

    0 讨论(0)
  • 2020-12-11 16:51
    1. There must be an installed (and selected) JDK in Eclipse:

      Window > Preferences > Java > Installed JREs

    2. The project must be configured to use that JDK:

      Project > Properties > Java Build Path > Libraries

    3. there should be an entry like "JRE System Library [JDK7]" in the list. If not press:

      Add Library... > JRE System Library

    4. The project should have been created as a "Java Project":

      Project > Properties > Builders

      should include "Java Builder"

    SoCodeIt IDE Dr

    0 讨论(0)
  • 2020-12-11 16:55

    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.

    0 讨论(0)
  • 2020-12-11 16:57

    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.

    0 讨论(0)
  • 2020-12-11 17:00

    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.

    0 讨论(0)
  • 2020-12-11 17:06

    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
    
    0 讨论(0)
提交回复
热议问题