LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Java noob - main() problem (https://www.linuxquestions.org/questions/programming-9/java-noob-main-problem-163831/)

AMMullan 03-29-2004 01:37 PM

Java noob - main() problem
 
Hey all :)

I've been using C for about 9 months and gotten reasonable confident in the language.. So i've now taken on Java - but when I go to compile the app it gives me an error saying I have an defined reference to main...

Here's the code:
Code:

class A {
  public static void main(String[] arguments) {
  String greeting = "Hello world!";
  System.out.println(greeting);
  }
}

But there is a main() in there... Heres the output when I compile:

[ammullan@daemon ammullan]$ gcj A.java
/usr/lib/gcc-lib/i386-redhat-linux/3.3.2/../../../crt1.o(.text+0x18): In function `_start':
: undefined reference to `main'
collect2: ld returned 1 exit status


Simple huh (boi and I thought I knew enuf to jump straight in)....

zombyLINUX 03-29-2004 01:44 PM

try making the class A public...

public class A {
stuff in class A...
}

AMMullan 03-29-2004 01:46 PM

I added public to class A but I still get the undefined main problem :-(

mpturner 03-29-2004 01:46 PM

that might do it...

if not use the '--main' command line argument (i think, check 'man gcj' for info)

AMMullan 03-29-2004 01:48 PM

Kewl, it worked using --main=A :D

Bit annoying that ya have to do that tho lol :D

Thanks for the help mpturner

zombyLINUX 03-29-2004 01:49 PM

Try compiling with javac...I just did and it worked fine.

Doesn't work also for gcj, maybe a bug in gcj or just have to use --main

AMMullan 03-29-2004 01:51 PM

Yeah I tried downloading the SDK last night but it crashed on me :(

Might try again tonight and then use that, although with gcj I can make binary files instead of class files :D

exodist 03-29-2004 02:52 PM

try changing class A to class main

AMMullan 03-29-2004 11:46 PM

No that still doesn't work properly, and it shouldn't matter what you call your class, just as long as you have public block called main :D


All times are GMT -5. The time now is 04:52 AM.