2

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.

dhke
  • 15,008
  • 2
  • 39
  • 56
Neuromeda
  • 95
  • 1
  • 2
  • 7

2 Answers2

5

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

bhspencer
  • 13,086
  • 5
  • 35
  • 44
-1

You are getting the error because you do not have a main method and if your program that you want to run does not have a main method JVM will not be able to run the program. In order to run and compile that program you need to have a main method for JVM to understand to compile that class.

below is the correct way: If you're not using the outer class, you can remove it.

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));
    }

    public static void main(String[] args) {
        Graphics g = new Graphics();
        g.run();
    }
}
Achrome
  • 7,773
  • 14
  • 36
  • 45
Anupama Rao
  • 107
  • 2