Jump to content

Exception In Thread "main"


yrstruly
 Share

Recommended Posts

HelloIm having trouble running java programs on my machine. All of the codes im running is giving this error message:Exception in thread "main" java.lang.NoSuchMethodError: mainWhat am i doing wrong, should i update or install a new sdk? I dont understand what is wrong, cause sometimes the code run smoothly without any message like the one given. I can compile the code and its giving me no errors, but when i execute it then its a different story. I have included an example code./* Chapter 10: Debugging Assignment: ***: 78983D-E Programmer: Suret Delport (Student No.: 10007349767) Date: 28 April 2008 Filename: Circle.java Purpose: Circle class = object of TestCircle class*/ public class Circle extends Shape{ public int x=22, y=44; // coordinates of the center private double radius; // Constructors public Circle() { setRadius(0); } public Circle(double r, int x, int y) { x=22; y=44; setRadius®; } // Get radius of Circle public double getRadius() { return radius; } // Set radius of Circle public void setRadius(double r) { radius = ( r >= 0 ? r : 0 ); } // Calculate area of Circle public double area() { return Math.PI * radius * radius; } // convert the Circle to a String public String toString() { return "Circle with center at <", " + y + "> " + "and radius = " + radius; } // return the class name public String getName() { return "Circle"; } // return the center location public String getLocation() { return "X = "+x+", "+"Y = "+y+" "; }}

Link to comment
Share on other sites

There's no "main" method in that code... it isn't meant to be run, after all - you are supposed to import and use it in another piece of code. If you try to actually execute it, the interpreter looks for a function called "main" to run, can't find it, and throws an exception.You can incorporate it into an executable script, for example:

class Example {	public static void main(String[] args) {		Circle circle = new Circle(3, 4, 5);		System.out.println(circle.getLocation());	}}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...