Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 825
aquero Avatar asked Jun 26 '11 14:06

aquero


People also ask

What is project classpath in eclipse?

The . classpath maintains the project's source and target references for Java compilation and compressed file or project dependencies. This configuration is maintained through the Java Build Path page in the project's properties.


2 Answers

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?

like image 136
jzilla Avatar answered Sep 19 '22 23:09

jzilla


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.

like image 31
Deepak Avatar answered Sep 22 '22 23:09

Deepak