aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Problem with getCodeBase() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem with getCodeBase()" Watch "Problem with getCodeBase()" New topic
Author

Problem with getCodeBase()

James Brooks
Gunslinger
Ranch Hand

Joined: Aug 17, 2006
Posts: 165
Hi again,

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.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39535
    
  27
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.


Ping & DNS - updated with new look and Ping home screen widget
James Brooks
Gunslinger
Ranch Hand

Joined: Aug 17, 2006
Posts: 165
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?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39535
    
  27
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with getCodeBase()
 
Similar Threads
scjp6 ch10 q.11
Extending BodyTagSupport (HFS CH10 Q9)
ch10 q11
Applet Image Animation
ch10 q2