Search code examples
javaacm-java-libraries

Eclipse cannot determine the main class


My code so far is:

package graphics;

import acm.graphics.*;
import acm.program.*;

public class project1 {
    public class graphics extends GraphicsProgram {
        private static final long serialVersionUID = 1L;
        public void run() {
            add( new GLabel( "hello, world", 100, 75));
        }
    }
}

I get the error:

Exception in thread "main" acm.util.ErrorException: Cannot determine the main class. at acm.program.Program.main(Program.java:1358)

I have gotten to this point with online references, except for two modifications that I did on my own account in run configurations, setting acm.program.Program as the main class in the Main tab, and also setting code=acm.program.Program as a program argument, not sure if this is relevant or not.


Solution

  • You need to remove your outer class project1. See the documentation here Figure 2-3:

    http://cs.stanford.edu/people/eroberts/jtf/tutorial/UsingTheGraphicsPackage.html

    package graphics;
    
    import acm.graphics.*;
    import acm.program.*;
    
    public class graphics extends GraphicsProgram {
            private static final long serialVersionUID = 1L;
            public void run() {
                add( new GLabel( "hello, world", 100, 75));
            }
    }
    

    Also you really should give your class a capitalized first letter.

    As pointed out by @BilltheLizard you also need to make sure that the name of your java file matches the name of your class. So if your class is called Graphics your java file should be called Graphics.java