This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes ColorText Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ColorText" Watch "ColorText" New topic


DB Ekanayake

Joined: Apr 07, 2008
Posts: 8

I got Following codes form a Java Tut.
They compiled without any errors.But when I try to run the program it Produced the following error.

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

Can any one spend your valuable time to solve this matter



import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.Font;
import java.awt.Color;

public class ColorText extends Canvas{

public void paint(Graphics g){
Font font;

font=new Font("Arial",Font.ITALIC | Font.BOLD,18);
g.drawString("Arial 18 point bold italic red",10,20);

Color mycolor =new Color(0,255,0);
font=new Font("Times new Roman",Font.BOLD,22);
g.drawString("Times new Roman 22 point plain green",10,40);

g.setColor(new Color(0,0,255));
font=new Font("Monospaced",Font.BOLD,20);
g.drawString("Monospaced 20 point plain blue",10,60);
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 41060
This code is not a standalone program - it's an AWT component. It can be used by embedding it in a Frame or some other kind of AWT container. To run it, the class would also need a main method, as the error message mentions.

Ping & DNS - my free Android networking tools app
wood burning stoves
subject: ColorText
Similar Threads
java database applet with Internet Explorer
How do i apply font styles and sizes to a string ?
Create Bar Chart
java database applet with Internet Explorer
java database applet with Internet Explorer