When I try to just display this image on the applet, I get a blank applet. My image, "Batty.gif", is stored with my jSmileFace class, in C:\Documents and Settings\Owner.Mynotebook\Ch12\src\ch10. Also, when I run file, I get a null pointer exception that points to getCodeBase(). The strange thing is, this project is named Ch10, not Ch12 (see my URL above). Would that have anything to do with the problem? My class and the Batty.gif image are clearly visible within my project Ch10 in NetBeans. Can anyone help me out? Error messages and code below:
compile-single: run-applet: java.lang.NullPointerException at java.applet.Applet.getCodeBase(Applet.java:152) at ch10.jSmileFace.<init>(jSmileFace.java:9) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at java.lang.Class.newInstance0(Class.java:355) at java.lang.Class.newInstance(Class.java:308) at sun.applet.AppletPanel.createApplet(AppletPanel.java:778) at sun.applet.AppletPanel.runLoader(AppletPanel.java:707) at sun.applet.AppletPanel.run(AppletPanel.java:361) at java.lang.Thread.run(Thread.java:619) BUILD SUCCESSFUL (total time: 2 minutes 39 seconds)
Hello. My name is Inigo Montoya. You killed my father. Prepare to die.
For the code to work as it is, the image, the "ch10" directory that includes the applet class, and the HTML file that includes the applet tag, all must be in the same directory, whichever one that is.
Joined: Aug 17, 2006
The .gif is located with the .java file, but I'm not using an HTML file; instead, I'm just running it using 'run file' in net beans. I don't have to use an HTML file, do I?
Joined: Mar 22, 2005
Maybe NetBeans can run applets in its own special way, but for deploying the applet to a server you'll need an HTML file. And the image must be with the HTML file (which constitutes the "code base" that the method name refers to).
I'd suggest to read up on creating applets without an IDE (it's easy). Then you get a better feel for these issues.