| | |
How come it gives this error when I run a program?
Thread Solved |
•
•
Join Date: Dec 2008
Posts: 65
Reputation:
Solved Threads: 1
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:
And I saved it as TestCircle.java
the constuctor file:
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.
Java Syntax (Toggle Plain Text)
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()); } }
the constuctor file:
Java Syntax (Toggle Plain Text)
/** * 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); } }
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.
•
•
Join Date: Sep 2009
Posts: 26
Reputation:
Solved Threads: 5
2
#2 Oct 7th, 2009
It's very simple:
... the class Circle doens't have any main method. So it's not an actual "program".
You should use:
First line will compile both classes.
Second line will run the class containing the main method.
(don't skip the basics
)
... the class Circle doens't have any main method. So it's not an actual "program".
You should use:
Java Syntax (Toggle Plain Text)
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
) Last edited by nomemory; Oct 7th, 2009 at 6:11 pm.
1
#4 Oct 7th, 2009
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!
If you have a quality, be proud of it and let it define you. Add it to the world!
If you got your answer, please mark the thread as Solved. It saves time when people are looking to contribute threads or for answers!
If you got your answer, please mark the thread as Solved. It saves time when people are looking to contribute threads or for answers!
![]() |
Similar Threads
- javac error message (Java)
- [Namespace Error]Only sometimes run the GUI.. (C#)
- Debug Error Run-Time Check Failure #2 (C++)
- Please correct the error in my program. When i run the program on turbo c++ 3,. (C++)
- Finding The Even Numbers DO NOT RUN PROGRAM (C++)
- Need help with runtime error in simple program (C++)
- Error while running program. Please help! (C#)
- run program and rename file script help please (Shell Scripting)
- Bus Error when I run my C++ program (C++)
- Error message when I run my program in C++ (C++)
Other Threads in the Java Forum
- Previous Thread: How come this program doesnt run?
- Next Thread: Extracting Mouse icon of the system
| Thread Tools | Search this Thread |
6 @param actuate android api applet application arc array arrays automation balls binary bluetooth bold business byte c++ chat class client code codesnippet collections compare component coordinates database defaultmethod detection doctype dragging ebook eclipse educational error file fractal froglogic game givemetehcodez graphics gui guitesting helpwithhomework hql html ide ideas image ingres input integer internet intersect invokingapacheantprogrammatically j2me java javaexcel javaprojects jni jpanel jtextarea julia linux list map method methods mobile mysql netbeans newbie nextline parameter php pong problem program programming project recursion recursive scanner sell server set sms sort sql string sun swing swt terminal threads tree web websites windows






