How to fix/workaround java.lang.reflect.InvocationTargetException

前端 未结 2 2016
终归单人心
终归单人心 2021-02-06 17:37

I\'ve got a question about a particularly annoying error that I haven\'t been able to figure out, much less overcome. Any time I try to run a Java applet (Applet or JApplet) on

相关标签:
2条回答
  • 2021-02-06 17:52

    I suggest that you read the Oracle Applet Development Tutorial. I'm not an expert on applets (understatement!) but you seem to be doing a lot of things differently to how the Tutorial says to do them. For instance, you don't use a main method to launch an applet, and you should be doing the setup in the init method not the constructor (see here).

    0 讨论(0)
  • 2021-02-06 17:56

    InvocationTargetException1 is thrown because the HTML is calling (trying to load) something that is not an applet. Change it to:

      <p><applet code="MainApplet" width="800" width="600">
      </applet></p>
    

    Also, as mentioned in the answer of Stephen C. Move the stuff from the constructor into the init() method.

    1. InvocationTargetException is a checked exception that wraps an exception thrown by an invoked method or constructor.

    Ensure the Java Console is configured to show for applets & JWS apps. If there is no output at the default level, raise it and try again.


    While I'm here: Why code an applet? If it is due to spec. by teacher, please refer them to Why CS teachers should stop teaching Java applets.

    0 讨论(0)
提交回复
热议问题