hey everybody,

this is my first post here. So first of all my apologies for any wrongdoings in the netiquette.

Yes, its from school, and its an example from the book, I recreate them to figure out what commands i need and to memorize them. But the problem is, that is doesn't seem to recognize the ButtonHandlers.. According to the book i should need: Import java.awt.event.*; to run events on. That doesn't seem to include those handlers though, what seems to be wrong that the program doesn't recognize them?

package school;

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

public class Applet5 extends Applet
// declaration
  Button button1;

  public void init()
    button1 = new Button( "click Here" );
    button1.addActionListener( new ButtonHandler() );
    add( button1 );
    setBackground ( Color.white );
  // internal class
  class ButtonHandler implements ActionListener
    public void actionPerformed( ActionEvent e );
      button1.setLabel("thank you!");
  } // end internal class


and this is the debug report that I get:

java.lang.ClassFormatError: school/Applet5$ButtonHandler (Code attribute is absent in method that is not abstract or native)
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:502)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:250)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:54)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:193)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
    at school.Applet5.init(Applet5.java:17)
    at com.borland.jbuilder.runtime.applet.AppletTestbed.startApplet(Unknown Source)
    at com.borland.jbuilder.runtime.applet.AppletTestbed.main(Unknown Source)

Exception in thread "main"

I really can't figure it out..

Recommended Answers

All 2 Replies

Member Avatar for iamthwee

It seems most of your errors stem from the school package.

Try commenting it out and get rid of the semicolon here:-

public void actionPerformed( ActionEvent e );

I'm not even sure if that is right, but I did that and it worked ok?

oh! Yes that did the trick, thank you very much iamthwee!

Doh! Such a simple mistake to make: a semicolon on the end of that, I should have seen it. I'll be more watchful the next time with those "public void" commands.


thanks again!


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.