html - Invocation target exception on Java applet -


i'm finishing project first java class, , i'm creating applet embedded html. i'm getting invocation target exception , can't figure out. of classes in same dir along html file , jar file. they're in file save of java projects, if location has it.

it's program 2 sub classes event listeners buttons in main class. it's meant count votes listeners, , runs normally, not html applet. don't think code of program going issue, here is:

 import java.awt.*;  import java.awt.event.*;   public class votes {       static int a;      static int b;      static textfield yescount;      static textfield nocount;       public static void main(string[] args) {           yeslistener yus = new yeslistener();          nolistener nos = new nolistener();          = 0;          b = 0;          frame frame = new frame("votes");          frame.setsize(600, 600);          frame.setvisible(true);           label label = new label("is java fun programming language?");          label.setbounds(50, 50, 400, 50);          frame.add(label);           nocount = new textfield("0");          nocount.setbounds(450, 400, 100, 50);          nocount.setforeground(color.red);          frame.add(nocount);           yescount = new textfield("0");          yescount.setbounds(50, 400, 100, 50);          yescount.setforeground(color.green);          frame.add(yescount);           button yes = new button("yes");          yes.setbounds(50, 500, 100, 50);          yes.addmouselistener(yus);          frame.add(yes);           button no = new button("no");          no.setbounds(450, 500, 100, 50);          no.addmouselistener(nos);          frame.add(no);           label lbl = new label();          frame.add(lbl);      }       static class yeslistener extends mouseadapter {           public void mouseclicked(mouseevent me) {               a++;              yescount.settext(a + " votes");          }      }       static class nolistener extends mouseadapter {           public void mouseclicked(mouseevent me) {               b++;              nocount.settext(b + " votes");          }      }  } 

i packed 3 classes jar file used archive. here html file use call class , archive jar file:

<html> <head> <title> votes </title> </head> <body> <applet code= "votes.class"  archive= "votes.jar"  width="600" height="600"> </applet> </body> </html> 

and exception java console looks this:

basic: exception: java.lang.reflect.invocationtargetexception. java.lang.runtimeexception: java.lang.reflect.invocationtargetexception     @ com.sun.deploy.uitoolkit.impl.awt.awtappletadapter.runonedtandwait(unknown     source) @ com.sun.deploy.uitoolkit.impl.awt.awtappletadapter.instantiateapplet(unknown source)     @ sun.plugin2.applet.plugin2manager.initappletadapter(unknown source)     @ sun.plugin2.applet.plugin2manager$appletexecutionrunnable.run(unknown source)     @ java.lang.thread.run(unknown source) caused by: java.lang.reflect.invocationtargetexception     @ com.sun.deploy.uitoolkit.impl.awt.oldpluginawtutil.invokeandwait(unknown source)     ... 5 more caused by: java.lang.classcastexception: votes cannot cast java.applet.applet     @ com.sun.deploy.uitoolkit.impl.awt.awtappletadapter$1.run(unknown source)     @ java.awt.event.invocationevent.dispatch(unknown source)     @ java.awt.eventqueue.dispatcheventimpl(unknown source)     @ java.awt.eventqueue.access$200(unknown source)     @ java.awt.eventqueue$3.run(unknown source)     @ java.awt.eventqueue$3.run(unknown source)     @ java.security.accesscontroller.doprivileged(native method)     @ java.security.protectiondomain$1.dointersectionprivilege(unknown source)     @ java.security.protectiondomain$1.dointersectionprivilege(unknown source)     @ java.awt.eventqueue$4.run(unknown source)     @ java.awt.eventqueue$4.run(unknown source)     @ java.security.accesscontroller.doprivileged(native method)     @ java.security.protectiondomain$1.dointersectionprivilege(unknown source)     @ java.awt.eventqueue.dispatchevent(unknown source)     @ java.awt.eventdispatchthread.pumponeeventforfilters(unknown source)     @ java.awt.eventdispatchthread.pumpeventsforfilter(unknown source)     @ java.awt.eventdispatchthread.pumpeventsforhierarchy(unknown source)     @ java.awt.eventdispatchthread.pumpevents(unknown source)     @ java.awt.eventdispatchthread.pumpevents(unknown source)     @ java.awt.eventdispatchthread.run(unknown source) basic: removed progress listener: sun.plugin.util.progressmonitoradapter@17c9937 

i've been searching answers while now, , feel exception doesn't give me enough information able sort out. give me appreciated, thanks.

applets don't use main method execute. applets subclasses of java.applet.applet , awt panels, rendered java.awt.panel. applets started init() , start() methods.

see the official java tutorials' article on applets learn how use applets.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -