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

丶灬走出姿态 提交于 2019-12-03 03:54:48
Andrew Thompson

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.

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).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!