Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

null pointer

 
zack chancery
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i wonder can you help me out?
i have two applets, Tracker and Trainer. Tracker references Trainer's trainer object.
Both applets access the same images from a base directory.
<code>
im1 = getImage(getCodeBase(),"template/final/set1c.jpg");waitForImage(im1);
im2 = getImage(getCodeBase(),"template/final/set1d.jpg");waitForImage(im2);
im3 = getImage(getCodeBase(),"template/final/set1e.jpg");waitForImage(im3);
</code>
However it seems to complain when the referenced applet tries to access the codebase and throws a null pointer exception:

java.lang.NullPointerException
at java.applet.Applet.getAppletContext(Applet.java:171)
at java.applet.Applet.getImage(Applet.java:226)
at java.applet.Applet.getImage(Applet.java:248)
at Trainer.init(Trainer.java:91)
at Tracker.init(Tracker.java:136)
at sun.applet.AppletPanel.run(AppletPanel.java:353)
at java.lang.Thread.run(Thread.java:534)

Trainer.java line 91: im1 = getImage(getCodeBase(),"template/final/set1c.jpg");waitForImage(im1);

Tracker.java line 136: trainer.init();
 
Joe Ess
Bartender
Posts: 9339
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We went through a similar problem in this thread. I think Ernest's comment is relevant to what you are observing:

every applet has an instance of an object called the "AppletStub". This is the applet's connection to the browser, and it supplies services like displaying status text, reporting the codebase URL, etc. If you just create the applet by hand, the stub will be null and many of the applet's methods will end up throwing a NullPointerException.

It is possible to fix this: you have to call the newly-created applet's "setStub" method and pass it an instance of a class you've defined which implements the AppletStub interface; your AppletStub can be implemented mostly by calling back to the original applet's various methods, especially the getAppletContext() method.

This would be easier if Applet had a "getStub()" method, but it doesn't.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic