0

I am using Eclipse Neon on windows 10, attempting to run the ManagerTest.java file from CoreJava 5.2 video and book.

There is a main type but for some reason, Eclipse is not recognizing it:

ManagerTest.java in Eclipse

I have tried adding inheritance as the source file in the Build Path, and that did not work. I also tried moving ManagerTest.java into the src folder but that did not work as well.

Each time I right click on the file and Run As a Java Application, I get the error.

Thanks in advance for your help.

Here is the code:

package inheritance;

/**
 * This program demonstrates inheritance.
 * @version 1.21 2004-02-21
 * @author Cay Horstmann
 */
public class ManagerTest
{
   public static void main(String[] args)
   {
      // construct a Manager object
      Manager boss = new Manager("Carl Cracker", 80000, 1987, 12, 15);
      boss.setBonus(5000);

      Employee[] staff = new Employee[3];

      // fill the staff array with Manager and Employee objects

      staff[0] = boss;
      staff[1] = new Employee("Harry Hacker", 50000, 1989, 10, 1);
      staff[2] = new Employee("Tommy Tester", 40000, 1990, 3, 15);

      // print out information about all Employee objects
      for (Employee e : staff)
         System.out.println("name=" + e.getName() + ",salary=" + e.getSalary());
   }
}
anonymous
  • 71
  • 2
  • 6
  • learn this http://stackoverflow.com/questions/12811618/eclipse-manually-select-main-class-for-executable-jar-file and this http://stackoverflow.com/questions/17397440/how-to-setup-main-class-in-run-configurations-in-eclipse – Youcef LAIDANI Feb 18 '17 at 08:47
  • Please don't put screenshots of code in questions. Copy and paste the text of the code. – slim Feb 18 '17 at 10:16

3 Answers3

0

Check that you have a class that has a method with a signature like.

public static void main(String args[])
{
    // something in here
}

The problem might be that it can't find a "main" so it has nowhere to start running your code from. Perhaps you mistyped or changed some aspect of the signature above.

hack_on
  • 2,532
  • 4
  • 26
  • 30
0

I contacted Professor Horstmann via email and he was kind enough to respond. He said all I needed to do is go to New-> Project ->JavaProject and point to the main chapter root in this case is v1ch05 (I was following both the video and book in live lessons on mysafari books online) from the download. Right click on the root folder Run As a Java Application and all the packages were created. I was able to then right click and run ManagerTest.java successfully.

anonymous
  • 71
  • 2
  • 6
0

Try to be in the parent directory of inheritance. Then, run in the shell: javac inheritance/ManagerTest.java java inheritance.ManagerTest

I guess you will just see the right output like me.