NullPointerException when trying to run an applet of multiple classes
I'm trying to display an applet in an html page. I've had success doing this in the past, but now that I have more than one class in the applet, I seem to get an error every time I try to load the applet in an html page. For a bit, I was writing the html page by hand, but then I realized the applet viewer in netbeans (the IDE I'm coding in) created an html page for you, which is the same as the one I was coding.
The application runs error-free when in the applet viewer, but the following message is displayed when I try to run it in the html page:
java.lang.NullPointerException
at sun.plugin2.applet.Plugin2Manager.findAppletJDKLevel(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.lang.NullPointerException
I tested another small, one class applet and it ran fine in the html p开发者_运维知识库age under the same conditions. Any ideas what may be wrong?
Definitely check the applet's classpath, as Jeff says. Also keep in mind that the security permissions work differently depending on how the applet is being run. The eclipse AppletViewer will let you get away with more lenient permissions than running the applet in a standalone HTML page.
If you are attempting any sort of read/writes to the file system, ensure that your jar is signed so that it can obtain the permissions necessary to perform its actions. An example: http://java.sun.com/developer/onlineTraining/Programming/JDCBook/signed.html
Additionally, this is probably already the case, but ensure you have an actual JDK installed on the machine running the applet, as opposed to simply a JRE.
I've seen this cryptic error message when you're missing required jars on your applet's classpath (archive tag). Are any of your classes referencing other classes that Eclipse might be resolving for you but that are not available when you actually run your applet?
精彩评论