Jump to content


Main Method Not Found


  • Please log in to reply
5 replies to this topic

#1 pp100

pp100

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 03 August 2012 - 02:26 PM

Hi.Could some one help. i used the JCreator applet templet to code the following applet.

import java.awt.*;
import java.applet.*;
import javax.swing.*;
/*applet code="LabelDemo"width=300 height200>
</applet>
*/

public class LabelDemo extends JApplet {

public void init() {

//public void start(){

Label one=new Label("one");
Label two=new Label("two");
Label three=new Label("three");
//add labels to applet window
add(one);
add(two);
add(three);
}


}

But when i try to run it i receive the error:

Error: Main method not found in class LabelDemo, please define the main method as:
   public static void main(String[] args)


I am a begginer in Java.I have tried to check previous forums but i seem not to get the answer.

Thanks in advance

#2 nyccanuck

nyccanuck

    Advanced Member

  • Members
  • PipPipPip
  • 78 posts

Posted 04 August 2012 - 02:50 PM

View Postpp100, on 03 August 2012 - 02:26 PM, said:

Hi.Could some one help. i used the JCreator applet templet to code the following applet.

But when i try to run it i receive the error:

Error: Main method not found in class LabelDemo, please define the main method as:
   public static void main(String[] args)


I am a begginer in Java.I have tried to check previous forums but i seem not to get the answer.

Thanks in advance

When you run a program you must have a main method:
public static void main(String[] args)

eg:
public class ProgramName
{
	public static void main(String[] args)
	{
		int value;
		...


#3 pp100

pp100

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 07 August 2012 - 10:55 AM

View Postpp100, on 03 August 2012 - 02:26 PM, said:

Hi.Could some one help. i used the JCreator applet templet to code the following applet.

import java.awt.*;
import java.applet.*;
import javax.swing.*;
/*applet code="LabelDemo"width=300 height200>
</applet>
*/

public class LabelDemo extends JApplet {

public void init() {

//public void start(){

Label one=new Label("one");
Label two=new Label("two");
Label three=new Label("three");
//add labels to applet window
add(one);
add(two);
add(three);
}


}

But when i try to run it i receive the error:

Error: Main method not found in class LabelDemo, please define the main method as:
   public static void main(String[] args)


I am a begginer in Java.I have tried to check previous forums but i seem not to get the answer.

Thanks in advance


#4 pp100

pp100

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 07 August 2012 - 10:58 AM

View Postnyccanuck, on 04 August 2012 - 02:50 PM, said:

When you run a program you must have a main method:
public static void main(String[] args)

eg:
public class ProgramName
{
	public static void main(String[] args)
	{
		int value;
		...


thanks but this is an applet and with applets what i have read) program execution begins on init().is this not so?

#5 nyccanuck

nyccanuck

    Advanced Member

  • Members
  • PipPipPip
  • 78 posts

Posted 07 August 2012 - 01:53 PM

View Postpp100, on 07 August 2012 - 10:58 AM, said:

thanks but this is an applet and with applets what i have read) program execution begins on init().is this not so?

To be honest, I am not sure as I do not deal with applets.  But what I can tell you is that your error message when you try to run your program says:

Quote

Error: Main method not found in class LabelDemo, please define the main method as:
public static void main(String[] args)

So looks to me like you are required to have a main method, or at the very least your program is looking for one.  Maybe someone else can comment on the applets.

#6 xinox

xinox

    Administrator

  • Admin
  • 525 posts

Posted 11 August 2012 - 03:02 PM

The template includes a HTML file which you need to host your applet.

Make sure the workspace has one or otherwise create a new project.

In the project settings window, select the HTML file as main/run.