Sally Gao
Sally Gao

Reputation: 1

Why does my Java code not run in Eclipse regardless of where I store the components?

I'm fairly new to using Java and Eclipse, and I'm trying to continue a project that someone else has created, which has been given to me in a set of folders, each containing several .Java documents (mainly classes). I'm using Eclipse EE, and I've tried writing a few simple programs of my own to get myself used to the general format of Eclipse, with success. However, I absolutely cannot get the project code to run. The steps that I took were:

  1. Created a new Project called SC (which automatically also created the src folder and the JRE System library)
  2. Added the project folders directly to the project folder SC by doing New > Folder (I did not put anything in src; I'm not sure if this might cause a problem)
  3. Click the Run button (I tried running as both a Java applet and a Java application)

Among the pre-existing folders from the original project is a main function, which is in a separate .Java file and not in any of the folders or the src folder, and uses some of the other Java classes. However, when I clicked 'Run' for the main file, it gave me the error "Editor does not contain a main type", which is clearly false. I'm not sure if this is because I didn't upload my folders to the src folder, or put all of the folders into the same package or something, but it simply doesn't run. I also tried rearranging the folders by adding them all into the src folder to see what would happen, but this resulted in a great number of errors whenever there is a line about importing Java packages like JPanel. I feel like the problem should be something simple to fix, but I can't figure out what it is because I have such a limited understanding of Eclipse. Help would be greatly appreciated.

Upvotes: 0

Views: 435

Answers (1)

E-Riz
E-Riz

Reputation: 32954

Without more details about the contents and structure that you've been given to work with, it's hard to give detailed advice. But Eclipse does include some good tutorials and documentation about setting up projects. Open Help > Help Contents and then navigate to Java development user guide > Getting Started Under there you'll find tutorials to help get started and configure projects of various layouts. I strongly recommend spending time going through that whole section of tutorials - it will pay off ten-fold in the long run; much better than floundering around yourself trying to learn both Java and Eclipse at the same time.

From the limited information presented, my first thought is that you don't have any of the Java code in your source folder (src); I think one or more of the tutorials will help you get things organized properly.

Upvotes: 1

Related Questions