Java forum for Java programmers

Eclipse - NoSuchMethodError: main

Mar 21, 2012 2:17 pm
William Colls

I think this is really an Eclipse problem.

When I try to run my program, I get the error message

NoSuchMethodFound: main

The file does in fact contain a main method, declared as public static
void, with no arguments.

I suspect that Eclipse is looking in the wrong place for the method, but
in every place that I can find in the various configurations, the file
that I am running is identified as the file containing containing the
main() method.

Any suggestions as to where further to look will greatfully received.

Thanks for your time.

William.

Mar 21, 2012 2:41 pm
Jussi Piitulainen
Re: Eclipse - NoSuchMethodError: main

William Colls writes:

> I think this is really an Eclipse problem.
>
> When I try to run my program, I get the error message
>
> NoSuchMethodFound: main
>
> The file does in fact contain a main method, declared as public static
> void, with no arguments.

Have you tried declaring it correctly?

Either: public static void main(String[] args)
or: public static void main(String... args).

<http://docs.oracle.com/javase/specs/jls/se7/html/jls-12.html#jls-12.1.4>


Mar 21, 2012 3:18 pm
Markspace
Re: Eclipse - NoSuchMethodError: main

On 3/21/2012 7:17 AM, William Colls wrote:
> I think this is really an Eclipse problem.
>
> When I try to run my program, I get the error message
>
> NoSuchMethodFound: main
>
> The file does in fact contain a main method, declared as public static
> void, with no arguments.


No arguments? In Java, the signature must match exactly. The argument
declaration is required.




Mar 21, 2012 8:41 pm
Lew
Re: Eclipse - NoSuchMethodError: main

William Colls wrote:
> I think this is really an Eclipse problem.

Nope.

> When I try to run my program, I get the error message
>
> NoSuchMethodFound: main
>
> The file does in fact contain a main method, declared as public static
> void, with no arguments.

It's a programmer problem.

> I suspect that Eclipse is looking in the wrong place for the method, but
> in every place that I can find in the various configurations, the file
> that I am running is identified as the file containing containing the
> main() method.
>
> Any suggestions as to where further to look will greatfully [sic] received.

Jussi and markspace explained the problem.

I will generalize the answer for you:

Do not suspect Eclipse first. Do not suspect Java first. Always suspect the programmer first.

Lew


Previous Thread: Fourier transform
Next Thread: Absolute beginner question

Related Forum Topics
Why does Eclipse find error in simple "public static void main( String[] args) { } instruction?
Am I crazy? I setup just the most simple java program in a new v3.6.2 Eclipse java project:


package aaa.bbb;

public static void main( String[] args) {
System.out.println("hello");
}


And Eclipse thinks the line

public static void main( String[] args) {

contains already an...
Exception in thread "main" java.awt.HeadlessException
I am having trouble getting a jar file to run properly.
1st I had logged into the Raspberry from my MAC using XQuartx xterm

bash-3.2$ssh -X pi@raspberrypi
pi@raspberrypi ~ $ echo $DISPLAY
localhost:10.0
pi@raspberrypi ~ $wish

I checked the xwindows system and found the...
Exception in thread "main" java.lang.NoClassDefFoundError: SendMailTLSDFC
Hi, I have created a java file for sending a file to my mail. I am
using mail.jar file. I am able to create .class file properly. But am
unable to run this file using java command on command prompt.
javac -cp D:\mail.jar SendMailTLSDFC.java
above command is working properly.
It creates 2...