Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » java.lang.NoSuchMethodError:main
java.lang.NoSuchMethodError:main [message #255182] Thu, 01 May 2008 14:34 Go to next message
Jonathan Camilleri is currently offline Jonathan CamilleriFriend
Messages: 91
Registered: July 2009
Member
The following program won't compile, although it compiled with a native
Java compiler. So far the problem only happened once.

Package - TestTwo

Mathz.java
----------
public class Mathz {
public static double Add (double aNumber1, double aNumber2) {
return (aNumber1 + aNumber2);
}

}

MathzTest.java
--------------
public class MathzTest {

public static void main() {
Mathz myMathz = new Mathz();
System.out.println(myMathz.Add(50, 50));
}

}
Error:
------
java.lang.NoSuchMethodError: main
Exception in thread "main"

Has this error occurred to anyone else please?
Re: java.lang.NoSuchMethodError:main [message #255190 is a reply to message #255182] Thu, 01 May 2008 15:06 Go to previous message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Jon,

What you describe sounds like a runtime error, not an compile time
error. The standard signature for the main method is

public static void main(String[] args)

so when you run a class, that's what the system will look for.

Note that since Add is a static method, you can do Mathz.add(50, 50);
i.e., you don't need an instance. Also note that standard Java
conventions would direct you to give all methods (except
constructors,which use the class' name) a name that starts with a lower
case letter.


Jon wrote:
> The following program won't compile, although it compiled with a
> native Java compiler. So far the problem only happened once.
>
> Package - TestTwo
>
> Mathz.java
> ----------
> public class Mathz {
> public static double Add (double aNumber1, double aNumber2) {
> return (aNumber1 + aNumber2);
> }
>
> }
>
> MathzTest.java
> --------------
> public class MathzTest {
>
> public static void main() {
> Mathz myMathz = new Mathz();
> System.out.println(myMathz.Add(50, 50));
> }
>
> }
> Error:
> ------
> java.lang.NoSuchMethodError: main
> Exception in thread "main"
> Has this error occurred to anyone else please?
>
>
>
>
>
>
Previous Topic:select code between braces
Next Topic:Breakpoint doesn't break
Goto Forum:
  


Current Time: Thu Mar 28 10:00:42 GMT 2024

Powered by FUDForum. Page generated in 0.03760 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top