Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Eclipse compiler creates "main(String[])" instead of "main(java.lang.String[])"
Eclipse compiler creates "main(String[])" instead of "main(java.lang.String[])" [message #225920] Thu, 16 March 2006 13:05 Go to next message
Eclipse UserFriend
I'm using Eclipse 3.1.2 on WinXP, with JDK 1.4.2

As an experiment, I created an Eclipse project from the "java-puzzlers"
source distribution. I then selected one of the source files,
"Change.java" and tried to run it. It said:

java.lang.NoSuchMethodError: main
Exception in thread "main"

That seemed pretty odd. I looked carefully at the class, and I didn't see
anything wrong with it. I then tried running "javap" on the class file,
and it showed me the following:

------------
Compiled from "Change.java"
public class Change extends java.lang.Object{
public Change();
Code:
0: aload_0
1: invokespecial #9; //Method java/lang/Object."<init>":()V
4: return
public static void main(String[]);
Code:
0: getstatic #21; //Field java/lang/System.out:Ljava/io/PrintStream;
3: ldc2_w #22; //double 0.8999999999999999d
6: invokevirtual #29; //Method java/io/PrintStream.println:(D)V
9: return
}
------------

This still seemed ok to me. Just in case, I tried executing the class
directly from the command line, using my 1.4.2 JDK. It got the same error.

Then, I tried compiling the source file directly from the command line,
using my 1.4.2 JDK. When I tried to execute this, it worked fine, not
reporting that error. I then ran "javap" again on this class, and got the
following:

-------------------
Compiled from "Change.java"
public class Change extends java.lang.Object{
public Change();
Code:
0: aload_0
1: invokespecial #1; //Method java/lang/Object."<init>":()V
4: return
public static void main(java.lang.String[]);
Code:
0: getstatic #2; //Field java/lang/System.out:Ljava/io/PrintStream;
3: ldc2_w #3; //double 0.8999999999999999d
6: invokevirtual #5; //Method java/io/PrintStream.println:(D)V
9: return
}
-------------------

There's only one difference in the two "javap" listings, the type of the
formal parameter to "main". The one that works is "java.lang.String[]",
and the one that fails is "String[]".

What's going on here?
Re: Eclipse compiler creates "main(String[])" instead of "main(java.lang.String[])&qu [message #225930 is a reply to message #225920] Thu, 16 March 2006 15:40 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: olivier_thomann.NOca.ibm.comSPAM

David Karr a écrit :
> I'm using Eclipse 3.1.2 on WinXP, with JDK 1.4.2
>
> As an experiment, I created an Eclipse project from the "java-puzzlers"
> source distribution. I then selected one of the source files,
> "Change.java" and tried to run it. It said
Could you please provide the source code as you typed it and we can
double check what is going on?
Thanks,
--
Olivier
Re: Eclipse compiler creates "main(String[])" instead of "main(java.lang.String[ [message #225937 is a reply to message #225930] Thu, 16 March 2006 16:02 Go to previous messageGo to next message
Eclipse UserFriend
public class Change {
public static void main(String args[]) {
System.out.println(2.00 - 1.10);
}
}
Re: Eclipse compiler creates "main(String[])" instead of "main(java.lang.String[ [message #225951 is a reply to message #225930] Thu, 16 March 2006 16:56 Go to previous messageGo to next message
Eclipse UserFriend
In case it's useful, the original repository for the source code I was
using is at:

http://www.javapuzzlers.com/java-puzzlers.zip
Re: Eclipse compiler creates "main(String[])" instead of "main(java.lang.String[ [message #225964 is a reply to message #225937] Thu, 16 March 2006 20:46 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: olivier_thomann.NOca.ibm.comSPAM

David Karr a écrit :
> public class Change {
> public static void main(String args[]) {
> System.out.println(2.00 - 1.10);
> }
> }
Works without a problem for me.
Are you sure you typed it without any error?
--
Olivier
Re: Eclipse compiler creates "main(String[])" instead of "main(java.lang.String[ [message #225971 is a reply to message #225964] Thu, 16 March 2006 22:53 Go to previous messageGo to next message
Eclipse UserFriend
Maybe I wasn't clear in the original note. I unzipped the distro into a
directory. I created a project from it. I didn't type it in. I will
also remind you that when I compiled the class with the regular 1.4.2 JDK,
it worked fine. It's only when I let Eclipse compile it that it doesn't
work.
Re: Eclipse compiler creates "main(String[])" instead of "main(java.lang.String[ [message #225979 is a reply to message #225951] Fri, 17 March 2006 02:17 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: varavamu.yahoo.com

Are you looking at StrungOut.java (from the same distro)?
------------------------------------------------------------ ---
public class StrungOut {
public static void main(String[] args) {
String s = new String("Hello world");
System.out.println(s);
}
}

class String {
private final java.lang.String s;

public String(java.lang.String s) {
this.s = s;
}

public java.lang.String toString() {
return s;
}
}
------------------------------------------------------------ ---
If so - this doesnt work because of the inner class String.

:)
Vijay

David Karr wrote:
> In case it's useful, the original repository for the source code I was
> using is at:
>
> http://www.javapuzzlers.com/java-puzzlers.zip
>
Re: Eclipse compiler creates "main(String[])" instead of "main(java.lang.String[ [message #226000 is a reply to message #225979] Fri, 17 March 2006 09:47 Go to previous message
Eclipse UserFriend
Good catch. I wasn't looking at that class. This appears to be the cause
of the problem. Once I excluded this class from the project and rebuilt
it, the "Change" class worked fine using the Eclipse-compiled code.
Previous Topic:JDT's Java editor complaining about "Access Restriction:" on an import
Next Topic:Content Assist in detail panes of Variables View while debugging
Goto Forum:
  


Current Time: Thu Jul 17 08:02:25 EDT 2025

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

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

Back to the top