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 10-23-2012, 01:10 PM   #1
amitshree
LQ Newbie
 
Registered: Oct 2012
Posts: 13

Rep: Reputation: Disabled
java applet:: main method not found


java prgrams is simply running in fedora17 terminal but when trying to run Applets then it shows the error
Error: Main method not found in class HelloWorld, please define the main method as:
public static void main(String[] args)
 
Old 10-23-2012, 02:22 PM   #2
kedarp
Member
 
Registered: Jul 2012
Distribution: Ubuntu
Posts: 198
Blog Entries: 3

Rep: Reputation: 23
Applets don't have a main method in Java. Then how can your program get the output.
Quote:
Error: Main method not found in class HelloWorld, please define the main method as:
public static void main(String[] args)
Did you extend the Applet class?
Quote:
public class HelloWorld extends Applet
 
Old 10-24-2012, 10:25 AM   #3
amitshree
LQ Newbie
 
Registered: Oct 2012
Posts: 13

Original Poster
Rep: Reputation: Disabled
i have extended the HelloWorld class but as the programs given in the book java the complete reference any of the program doesn't contain main method....and the same program i am able to run from eclipse but not from terminal
 
Old 10-24-2012, 10:57 AM   #4
amitshree
LQ Newbie
 
Registered: Oct 2012
Posts: 13

Original Poster
Rep: Reputation: Disabled
here is a program sample
import java.awt.Graphics;
public class HelloWorld extends java.applet.Applet {
public void init() {
resize(150,25);
}
public void paint(Graphics g) {
g.drawString("Hello world!", 50, 25);
}
}
 
Old 10-25-2012, 12:02 PM   #5
kedarp
Member
 
Registered: Jul 2012
Distribution: Ubuntu
Posts: 198
Blog Entries: 3

Rep: Reputation: 23
Code:
import java.awt.Graphics;


/*<applet code="HelloWorld"></applet>*/


public class HelloWorld extends java.applet.Applet {

    public void init() 
    {
    resize(150,25);
    }
    public void paint(Graphics g) 
    {
    g.drawString("Hello world!", 50, 25);
    }
}
The code is correct. But when you run from terminal, it will not run till you add the bold lines.

Applets are loaded in a browser. So, either you can create a HTML file named HelloWorld and add the <applet> tag to it.
Or you can add the tag in the Java file itself as above.
And run the program.
Code:
$javac Helloworld.java
$appletviewer Helloworld.java
 
  


Reply

Tags
java



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
AWN Dock AWN Main Menu applet : could not create applet AMA Linux - Software 10 09-08-2011 06:20 AM
JAVA: Popup menu in diffrent class then main Applet, how to repaint()? Valkyrie_of_valhalla Programming 2 10-24-2009 03:14 PM
Exception in thread "main" java.lang.ClassFormatError: onmyown.Main (unrecognized cla zimboney Fedora 4 07-20-2007 01:00 PM
how do you reload the 'main' method in Java? ludeKing Programming 1 05-29-2004 10:22 PM
How to pass a file name into the main Method (C/C++) shassouneh Programming 2 06-20-2002 08:07 PM

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

All times are GMT -5. The time now is 01:26 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