Hi everyone iam trying to learn awt and applets. The code below has compiled well but when i run it iam getting an Exception in thread main "Java.lang.NoSuchMethodError". Could any1 pls tell me where i have gone wrong.

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class ButtonTest extends Applet
{
Button b1;
public void init()
{
Button b1= new Button("OK");
add(b1);
}
}

Recommended Answers

All 5 Replies

Are you trying to run this program as a console application? Applets are not run the same way console applications are in Java. Java.exe is used to run applications whereas AppletViewer.exe is used to run applets.

Regards,

~Tyler S. Breton

Member Avatar for Dukane

Your applet runs just fine in a web browser. But as Tyler said, this program will not run as a console application.

Hi Dukane ,

I ve run it using an appletviewer and webbrowser. But iam facing the same problem. I continue to get the same error which i have specified bfore. I ve even checked my browser settings(firefox) and enabled Java for it. I ve also saved both the html and java file in the same directory still the problem continues.

Compiles and runs fine for me.

Member Avatar for Dukane

Try updating your JRE and JDK. I have the latest version and it works fine for me. I made no changes.

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.