LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-29-2004, 01:37 PM   #1
AMMullan
Member
 
Registered: Sep 2003
Location: United Kingdom
Distribution: Ubuntu, Arch
Posts: 438

Rep: Reputation: 30
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)....
 
Old 03-29-2004, 01:44 PM   #2
zombyLINUX
LQ Newbie
 
Registered: Mar 2004
Distribution: SuSE 9.0 KDE 3.1
Posts: 26

Rep: Reputation: 15
try making the class A public...

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

Last edited by zombyLINUX; 03-29-2004 at 01:45 PM.
 
Old 03-29-2004, 01:46 PM   #3
AMMullan
Member
 
Registered: Sep 2003
Location: United Kingdom
Distribution: Ubuntu, Arch
Posts: 438

Original Poster
Rep: Reputation: 30
I added public to class A but I still get the undefined main problem :-(
 
Old 03-29-2004, 01:46 PM   #4
mpturner
LQ Newbie
 
Registered: Mar 2004
Posts: 1

Rep: Reputation: 0
that might do it...

if not use the '--main' command line argument (i think, check 'man gcj' for info)
 
Old 03-29-2004, 01:48 PM   #5
AMMullan
Member
 
Registered: Sep 2003
Location: United Kingdom
Distribution: Ubuntu, Arch
Posts: 438

Original Poster
Rep: Reputation: 30
Kewl, it worked using --main=A

Bit annoying that ya have to do that tho lol

Thanks for the help mpturner
 
Old 03-29-2004, 01:49 PM   #6
zombyLINUX
LQ Newbie
 
Registered: Mar 2004
Distribution: SuSE 9.0 KDE 3.1
Posts: 26

Rep: Reputation: 15
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

Last edited by zombyLINUX; 03-29-2004 at 01:50 PM.
 
Old 03-29-2004, 01:51 PM   #7
AMMullan
Member
 
Registered: Sep 2003
Location: United Kingdom
Distribution: Ubuntu, Arch
Posts: 438

Original Poster
Rep: Reputation: 30
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
 
Old 03-29-2004, 02:52 PM   #8
exodist
Senior Member
 
Registered: Aug 2003
Location: Portland, Oregon
Distribution: Arch
Posts: 1,374

Rep: Reputation: 47
try changing class A to class main
 
Old 03-29-2004, 11:46 PM   #9
AMMullan
Member
 
Registered: Sep 2003
Location: United Kingdom
Distribution: Ubuntu, Arch
Posts: 438

Original Poster
Rep: Reputation: 30
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Java 'Main' exception question magnumbi Programming 2 10-11-2005 12:41 PM
Starting Java from shell script (Exception in thread "main") rolf_mueller Linux - Software 5 10-30-2004 02:11 AM
Java error "Exception in thread "main" java.lang.StackOverflowError" nro Programming 1 09-04-2004 03:47 AM
how do you reload the 'main' method in Java? ludeKing Programming 1 05-29-2004 10:22 PM
What is the main used program for coding Java? Tyir Programming 2 10-20-2003 08:10 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration