Jump to content

Exception In Thread "main"


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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...