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

Viewed 34841

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

4 Answers

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