How to solve java.lang.NoSuchMethodError: main Exception in thread "main"

when i run it produce

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

this is coding

import java.awt.; 
import java.applet.;

public class Sepah extends Applet{ 
public void paint(Graphics g){

    g.setColor(Color.green);
    g.drawLine(100,100,10,140);
    g.drawLine(100,100,150,120);
    g.drawLine(290,120,400,130);
    g.drawLine(410,130,500,100);

    g.setColor(Color.black);
    g.drawLine(150,80,220,40);
    g.drawLine(220,40,290,80);


    g.setColor(Color.yellow);
    g.fillRect(150,80,140,140);


    g.setColor(Color.orange);
    g.fillRect(170,110,40,40);


    g.setColor(Color.orange);
    g.fillRect(230,110,40,40);


    g.setColor(Color.black);
    g.fillRect(400,80,15,150);

    g.setColor(Color.green);
    g.fillRect(210,180,20,40);

    g.setColor(Color.green);
    g.fillOval(315,20,180,68);

    g.setColor(Color.orange);
    g.fillRect(210,180,20,40);

Graphics2D g2d=(Graphics2D) g;
g2d.drawString("", 190,100);

g.setColor(Color.red);
g.fillRect(150,360,300,50);

g.setColor(Color.red);
g.fillRect(200,325,200,50);

g.setColor(Color.black);
g.fillRect(211,330,80,25);

g.setColor(Color.black);
g.fillRect(290,330,80,25);

g.setColor(Color.yellow);
g.fillRect(410,365,30,18);


g.setColor(Color.black);
g.fillOval(170,385,50,50);

g.setColor(Color.black);
g.fillOval(390,385,50,50);

g.setColor(Color.black);
g.fillRect(200,362,195,30);

g.setColor(Color.red);
g.fillRect(300,330,3,70);

g.setColor(Color.white);
g.fillOval(175,389,40,40);

g.setColor(Color.white);
g.fillOval(395,389,40,40);
} 
}

Recommended Answers

All 4 Replies

this has nothing to do with not being able to produce output: the file can't run since it has no main method, which would be the entry point for the program.

It is an applet. It needs to be run as part of a webpage, and it works just fine when you use it like that. It draws a car, a house, and a tree with some hills in the background.

hmmm ... just checked the error message, didn't really went over the code, so I kind off missed that.
bguild is right, but this brings me to the question:
did you write this code? somehow I would think that someone that writes the code for an applet knows what an applet is and how it works.

First of all I want to correct your code.
You have used this

import java.awt.;
import java.applet.; "

Correct it by by using asterisk to import all the classes of awt and applet package i.e

import java.awt.*; 
import java.applet.*;

And it is an applet thats why it doesnt have main method. If you are doing this on NetBeans Platform ,then first make it an Web App then instead of new java file , click on applet and paste this code there.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.