Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #13097 > unrolled thread
| Started by | William Colls <william.colls@rogers.com> |
|---|---|
| First post | 2012-03-21 10:17 -0400 |
| Last post | 2012-03-23 18:05 +0100 |
| Articles | 15 — 11 participants |
Back to article view | Back to comp.lang.java.programmer
Eclipse - NoSuchMethodError: main William Colls <william.colls@rogers.com> - 2012-03-21 10:17 -0400
Re: Eclipse - NoSuchMethodError: main Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2012-03-21 16:41 +0200
Re: Eclipse - NoSuchMethodError: main markspace <-@.> - 2012-03-21 08:18 -0700
Re: Eclipse - NoSuchMethodError: main Lew <lewbloch@gmail.com> - 2012-03-21 13:41 -0700
Re: Eclipse - NoSuchMethodError: main Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-03-21 20:46 -0400
Re: Eclipse - NoSuchMethodError: main Arne Vajhøj <arne@vajhoej.dk> - 2012-03-21 21:00 -0400
Re: Eclipse - NoSuchMethodError: main BGB <cr88192@hotmail.com> - 2012-03-21 21:59 -0700
Re: Eclipse - NoSuchMethodError: main Patricia Shanahan <pats@acm.org> - 2012-03-22 03:13 -0700
Re: Eclipse - NoSuchMethodError: main Arne Vajhøj <arne@vajhoej.dk> - 2012-03-22 21:46 -0400
Re: Eclipse - NoSuchMethodError: main Lew <lewbloch@gmail.com> - 2012-03-22 18:49 -0700
Re: Eclipse - NoSuchMethodError: main Gene Wirchenko <genew@ocis.net> - 2012-03-22 22:17 -0700
Re: Eclipse - NoSuchMethodError: main William Colls <william.colls@rogers.com> - 2012-03-23 09:36 -0400
Re: Eclipse - NoSuchMethodError: main Lew <noone@lewscanon.com> - 2012-03-23 07:51 -0700
Re: Eclipse - NoSuchMethodError: main Patricia Shanahan <pats@acm.org> - 2012-03-23 08:49 -0700
Re: Eclipse - NoSuchMethodError: main Jan Burse <janburse@fastmail.fm> - 2012-03-23 18:05 +0100
| From | William Colls <william.colls@rogers.com> |
|---|---|
| Date | 2012-03-21 10:17 -0400 |
| Subject | Eclipse - NoSuchMethodError: main |
| Message-ID | <jkcntd$sf1$1@theodyn.ncf.ca> |
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.
[toc] | [next] | [standalone]
| From | Jussi Piitulainen <jpiitula@ling.helsinki.fi> |
|---|---|
| Date | 2012-03-21 16:41 +0200 |
| Message-ID | <qotty1i818o.fsf@ruuvi.it.helsinki.fi> |
| In reply to | #13097 |
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>
[toc] | [prev] | [next] | [standalone]
| From | markspace <-@.> |
|---|---|
| Date | 2012-03-21 08:18 -0700 |
| Message-ID | <jkcrg4$sqp$1@dont-email.me> |
| In reply to | #13097 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Lew <lewbloch@gmail.com> |
|---|---|
| Date | 2012-03-21 13:41 -0700 |
| Message-ID | <15830333.3.1332362469516.JavaMail.geo-discussion-forums@pbcuk5> |
| In reply to | #13097 |
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
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@ieee-dot-org.invalid> |
|---|---|
| Date | 2012-03-21 20:46 -0400 |
| Message-ID | <jkdsop$hsm$1@dont-email.me> |
| In reply to | #13097 |
On 3/21/2012 10: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.
>
> 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.
Others have explained that "main" must have a parameter list
consisting of exactly one String array. For completeness' sake,
it's *possible* to have a "main" with some other signature; as with
any other method, you can overload "main" as you wish:
public static void main(String[] args) { ... }
public static int main() { return 42; }
public static double main(String justOneArg) {
return Double.parseDouble(justOneArg);
}
...
However, the particular "main" that Java (not just Eclipse) looks
for when starting execution is the one and only "main" that has the
first form above. (You can write "String... args" instead of
"String[] args" if you like, but it's the same thing. Java starts
with the "main" whose parameter list is one String array, however
you happen to express it.)
Only the type of the formal parameter matters; the actual name
is irrelevant. When the arguments aren't used, my own personal
practice is to write
public static void main(String[] unused) { ... }
The only drawback is that code-policing tools sometimes insist
that I write Javadoc comments for the "unused" parameter ;-)
--
Eric Sosman
esosman@ieee-dot-org.invalid
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2012-03-21 21:00 -0400 |
| Message-ID | <4f6a79a0$0$282$14726298@news.sunsite.dk> |
| In reply to | #13113 |
On 3/21/2012 8:46 PM, Eric Sosman wrote:
> Only the type of the formal parameter matters; the actual name
> is irrelevant. When the arguments aren't used, my own personal
> practice is to write
>
> public static void main(String[] unused) { ... }
>
> The only drawback is that code-policing tools sometimes insist
> that I write Javadoc comments for the "unused" parameter ;-)
That could be considered a good opportunity to put in some
funny comments!
Arne
[toc] | [prev] | [next] | [standalone]
| From | BGB <cr88192@hotmail.com> |
|---|---|
| Date | 2012-03-21 21:59 -0700 |
| Message-ID | <jkebm2$r9t$1@news.albasani.net> |
| In reply to | #13115 |
On 3/21/2012 6:00 PM, Arne Vajhøj wrote:
> On 3/21/2012 8:46 PM, Eric Sosman wrote:
>> Only the type of the formal parameter matters; the actual name
>> is irrelevant. When the arguments aren't used, my own personal
>> practice is to write
>>
>> public static void main(String[] unused) { ... }
>>
>> The only drawback is that code-policing tools sometimes insist
>> that I write Javadoc comments for the "unused" parameter ;-)
>
> That could be considered a good opportunity to put in some
> funny comments!
>
yep, and maybe go into some long rant about something almost entirely
irrelevant (hmm... sadly not too far from the truth sometimes...).
[toc] | [prev] | [next] | [standalone]
| From | Patricia Shanahan <pats@acm.org> |
|---|---|
| Date | 2012-03-22 03:13 -0700 |
| Message-ID | <DfWdnUazsO7YZvfSnZ2dnUVZ_qadnZ2d@earthlink.com> |
| In reply to | #13119 |
BGB wrote:
> On 3/21/2012 6:00 PM, Arne Vajhøj wrote:
>> On 3/21/2012 8:46 PM, Eric Sosman wrote:
>>> Only the type of the formal parameter matters; the actual name
>>> is irrelevant. When the arguments aren't used, my own personal
>>> practice is to write
>>>
>>> public static void main(String[] unused) { ... }
>>>
>>> The only drawback is that code-policing tools sometimes insist
>>> that I write Javadoc comments for the "unused" parameter ;-)
>>
>> That could be considered a good opportunity to put in some
>> funny comments!
>>
>
> yep, and maybe go into some long rant about something almost entirely
> irrelevant (hmm... sadly not too far from the truth sometimes...).
How about "This comment is intentionally left empty."?
Patricia
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2012-03-22 21:46 -0400 |
| Message-ID | <4f6bd5e9$0$289$14726298@news.sunsite.dk> |
| In reply to | #13121 |
On 3/22/2012 6:13 AM, Patricia Shanahan wrote:
> BGB wrote:
>> On 3/21/2012 6:00 PM, Arne Vajhøj wrote:
>>> On 3/21/2012 8:46 PM, Eric Sosman wrote:
>>>> Only the type of the formal parameter matters; the actual name
>>>> is irrelevant. When the arguments aren't used, my own personal
>>>> practice is to write
>>>>
>>>> public static void main(String[] unused) { ... }
>>>>
>>>> The only drawback is that code-policing tools sometimes insist
>>>> that I write Javadoc comments for the "unused" parameter ;-)
>>>
>>> That could be considered a good opportunity to put in some
>>> funny comments!
>>>
>>
>> yep, and maybe go into some long rant about something almost entirely
>> irrelevant (hmm... sadly not too far from the truth sometimes...).
>
> How about "This comment is intentionally left empty."?
@param unused What do you think?
@param unused To be used or not to be used that is the question!
:-)
Arne
[toc] | [prev] | [next] | [standalone]
| From | Lew <lewbloch@gmail.com> |
|---|---|
| Date | 2012-03-22 18:49 -0700 |
| Message-ID | <1204263.284.1332467382680.JavaMail.geo-discussion-forums@pbcp5> |
| In reply to | #13126 |
Arne Vajhøj wrote: > @param unused What do you think? > @param unused To be used or not to be used that is the question! > > :-) * @param unused as I am to public speaking, I stand before you ... -- Lew
[toc] | [prev] | [next] | [standalone]
| From | Gene Wirchenko <genew@ocis.net> |
|---|---|
| Date | 2012-03-22 22:17 -0700 |
| Message-ID | <2q1om7l9mc8drrae6085m4pna6ut950d18@4ax.com> |
| In reply to | #13127 |
On Thu, 22 Mar 2012 18:49:42 -0700 (PDT), Lew <lewbloch@gmail.com>
wrote:
>Arne Vajhøj wrote:
>> @param unused What do you think?
>> @param unused To be used or not to be used that is the question!
>>
>> :-)
>
>* @param unused as I am to public speaking, I stand before you ...
You need The Commentator:
http://www.cenqua.com/commentator/
Sincerely,
Gene Wirchenko
[toc] | [prev] | [next] | [standalone]
| From | William Colls <william.colls@rogers.com> |
|---|---|
| Date | 2012-03-23 09:36 -0400 |
| Message-ID | <jkhu82$6ec$1@theodyn.ncf.ca> |
| In reply to | #13113 |
On 03/21/2012 08:46 PM, Eric Sosman wrote:
> On 3/21/2012 10: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.
>>
>> 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.
>
> Others have explained that "main" must have a parameter list
> consisting of exactly one String array. For completeness' sake,
> it's *possible* to have a "main" with some other signature; as with
> any other method, you can overload "main" as you wish:
>
> public static void main(String[] args) { ... }
> public static int main() { return 42; }
> public static double main(String justOneArg) {
> return Double.parseDouble(justOneArg);
> }
> ...
>
> However, the particular "main" that Java (not just Eclipse) looks
> for when starting execution is the one and only "main" that has the
> first form above. (You can write "String... args" instead of
> "String[] args" if you like, but it's the same thing. Java starts
> with the "main" whose parameter list is one String array, however
> you happen to express it.)
>
> Only the type of the formal parameter matters; the actual name
> is irrelevant. When the arguments aren't used, my own personal
> practice is to write
>
> public static void main(String[] unused) { ... }
>
> The only drawback is that code-policing tools sometimes insist
> that I write Javadoc comments for the "unused" parameter ;-)
>
Thanks to all who replied. I changed the the signature to
public static void(String[] args)
but it made no difference - same problem.
I made the assumption that it was/is an Eclipse configuration issue,
based on the fact that When I first started with Java, I was using the
Netbeans IDE, and the main() worked perfectly well there, but I would
get the NoSuchMethodError if project setup page didn't point to the
correct file.
I have side-stepped the problem by creating a small class that does have
a main method, imports the class I have defined and am building, and
then instansiates an object form it, and invokes the methods I need to
test. Better solution, as it more closely the real world use of the work
I am doing.
Again thanks to all for your helpful responses.
William.
[toc] | [prev] | [next] | [standalone]
| From | Lew <noone@lewscanon.com> |
|---|---|
| Date | 2012-03-23 07:51 -0700 |
| Message-ID | <jki2m2$uj3$1@news.albasani.net> |
| In reply to | #13132 |
On 03/23/2012 06:36 AM, William Colls wrote:
> On 03/21/2012 08:46 PM, Eric Sosman wrote:
>> On 3/21/2012 10: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.
>>>
>>> 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.
>>
>> Others have explained that "main" must have a parameter list
>> consisting of exactly one String array. For completeness' sake,
>> it's *possible* to have a "main" with some other signature; as with
>> any other method, you can overload "main" as you wish:
>>
>> public static void main(String[] args) { ... }
>> public static int main() { return 42; }
>> public static double main(String justOneArg) {
>> return Double.parseDouble(justOneArg);
>> }
>> ...
>>
>> However, the particular "main" that Java (not just Eclipse) looks
>> for when starting execution is the one and only "main" that has the
>> first form above. (You can write "String... args" instead of
>> "String[] args" if you like, but it's the same thing. Java starts
>> with the "main" whose parameter list is one String array, however
>> you happen to express it.)
>>
>> Only the type of the formal parameter matters; the actual name
>> is irrelevant. When the arguments aren't used, my own personal
>> practice is to write
>>
>> public static void main(String[] unused) { ... }
>>
>> The only drawback is that code-policing tools sometimes insist
>> that I write Javadoc comments for the "unused" parameter ;-)
>>
> Thanks to all who replied. I changed the the signature to
>
> public static void(String[] args)
>
> but it made no difference - same problem.
That would fail to compile.
Please prepare an SSCCE for us.
http://sscce.org/
> I made the assumption that it was/is an Eclipse configuration issue, based on
> the fact that When I first started with Java, I was using the Netbeans IDE,
> and the main() worked perfectly well there, but I would get the
> NoSuchMethodError if project setup page didn't point to the correct file.
What happens when you invoke it via "java" on the command line?
> I have side-stepped the problem by creating a small class that does have a
> main method, imports the class I have defined and am building, and then
This makes no sense at all. Something there is you have not told us, mmm.
> instansiates an object form it, and invokes the methods I need to test. Better
> solution, as it more closely the real world use of the work I am doing.
--
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
[toc] | [prev] | [next] | [standalone]
| From | Patricia Shanahan <pats@acm.org> |
|---|---|
| Date | 2012-03-23 08:49 -0700 |
| Message-ID | <paCdnVNHW90-BvHSnZ2dnUVZ_vednZ2d@earthlink.com> |
| In reply to | #13133 |
On 3/23/2012 7:51 AM, Lew wrote: > On 03/23/2012 06:36 AM, William Colls wrote: ... >> Thanks to all who replied. I changed the the signature to >> >> public static void(String[] args) >> >> but it made no difference - same problem. > > That would fail to compile. > > Please prepare an SSCCE for us. > http://sscce.org/ It may be a package issue. Patricia
[toc] | [prev] | [next] | [standalone]
| From | Jan Burse <janburse@fastmail.fm> |
|---|---|
| Date | 2012-03-23 18:05 +0100 |
| Message-ID | <jkiagl$fob$1@news.albasani.net> |
| In reply to | #13097 |
There is a difference between:
NoSuchMethodException (1)
And
NoSuchMethodError (2)
If you get (1) then all your classes could load,
but the method in question does not exist. If
you get (2) then a problem existed during the
load of your classes in the first place.
The difference is indicated by the different
super class chain of the two exceptions:
NoSuchMethodException (1)
ReflectiveOperationException
Exception
And
NoSuchMethodError (2)
IncompatibleClassChangeError
LinkageError
Error
I observed that the XXXErrors can easily happend
when incompatible versions of compiled .jars are
mixed. For example I had the case, compiled
B against A.jar:
class A; in A.jar
class B extends A; in B.jar
Now had a different version of A, call it A2.jar
final class A; in A2.jar
When I tried to run A2.jar+B.jar one gets typically
a linkage error, since A is suddently final and
not supposed to be extended. Similar things can
happend with other expectations inside a class
that cannot be resolved at runtime.
Bye
William Colls schrieb:
> 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.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web