I copied this code from the textbook, so the code should have no mistake? I typed the contructor file(I think thats what its called) and the actual codes. So the code looks like this:

public class TestCircle { 
  public static void main(String[] args) { 
    Circle spot = new Circle(); 
    
    spot.setRadius(5);
    
    System.out.println("Circle radius:" + spot.getRadius());
    System.out.println("Circle area: " + spot.area()); 
    
  }
}

And I saved it as TestCircle.java

the constuctor file:

/** 
 * Circle class.
 */
public class Circle {
  private static final double PI = 3.14;
  private double radius; 
    
  /** 
   * constructor 
   * pre: none
   * post: A circle object created. Radius initialized to 1.
   */ 
  public Circle() {
      radius = 1;          //default radius
  } 
  
  
  /** 
   * Changes the radius of the circle.
   * pre: none
   * post: radius has been changed.
   */ 
  public void setRadius(double newRadius) { 
    radius = newRadius; 
  } 
  
  
  /**
   * Calculates the area of the circle. 
   * pre: none
   * post: The area of the circle has been returned.
   */ 
  public double area() { 
    double circleArea; 
    
    circleArea = PI * radius * radius; 
    return(circleArea);
  } 
  
  
  /**
   * Returns the radius of the circle.
   * pre: none
   * post: The radius of the circle has been returned
   */ 
  public double getRadius() {
    return(radius);
  }
}

Saved it as Circle.java

When I compile it, it's fine.. no errors but when I go to see the ouput it gives me this:

> java Circle
Static Error: No static method in Circle with name 'main' accepts arguments (String[])

What does that mean, how do I fix it?
I think this happens to most of the programs I to run.

Recommended Answers

All 4 Replies

It's very simple:
... the class Circle doens't have any main method. So it's not an actual "program".

You should use:

javac Circle.java TestCircle.java
java TestCircle

First line will compile both classes.
Second line will run the class containing the main method.

(don't skip the basics:P)

commented: Good post. :) +3

What do u mean?
Like save it as that name?

nomemory means compile the classes then run TestCircle. You cannot run Circle directly as it has no main method. main is the entry point for you program. As nomemory said, don't skip the basics. Please mark your other thread as solved as well! :)

oh ok, I got now.. got it to output.
So it's like instead of running the constructor file(circle) run the actual code program instead.. k thx. I'll mark the other one solve too but I can't find where it is, how do i find it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.