开发者

"The project: swing which is referenced by the classpath, does not exist" in Eclipse when project name is the same as workspace name

I am new to swing development using eclipse but I have been using eclipse for my java code development for more than a year. Today when I wrote a sam开发者_如何学Cple swing class got a curious error from eclipse.

I created a workspace swing , and created a new project in the same name as the workspace. Then wrote a sample class inside the project, please find the code below.

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;


public class SwingDemo {

    public SwingDemo() {
        // TODO Auto-generated constructor stub
        JFrame jFrame = new JFrame("A sample swing application");
        jFrame.setSize(275, 100);

        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JLabel jLabel = new JLabel("Welcome to swing!!!!");
        jFrame.add(jLabel);

        jFrame.setVisible(true);
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                new SwingDemo();
            }
        });

    }

}

When I tried to execute it in eclipse ,resulted in the below error

The project: swing which is referenced by the classpath, does not exist.

The same code was executed fine, when the project name and workspace name were differrent.

I am just curious, what caused this error. Please help


I have faced the same problem as you did. Do not give the Project and Workspace the same name. If this is the case then give different names and rebuild it. It will work.


In the project properties, in the "Java Build Path" section and the "Projects" tab, is a list of other projects that this project depends on. When you view this, you should see at least one red marker in the list of projects, on the line that lists the "xxxxxx" project. If you don't really need that project, then select that line and click "Remove" and "OK". If that just creates other problems, then you'll have to figure out what was supposed to be in that missing project and get it created. Perhaps there's another project in your workspace with a slightly different name that represents what your project needs?


One reason for the error might be that you have used same name for both Workspace and Project.

Changing it and rebuilding should resolve the issue in that case.


Verify your root .classpath file does not have invalid entries. These did not show up in the Preferences -> Build -> Classpath

</classpathentry>
<classpathentry kind="src" path="/src"/>
<classpathentry kind="lib" path="log4j.xml"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜