Applet.getAppletContext() returns null pointer exception

Can anyone tell me why I'm getting a null pointer exception in my JApplet when I try to access the AppletContext?

Exception occurred during event dispatching:

java.lang.NullPointerException

at java.applet.Applet.getAppletContext(Applet.java:141)

The code is as follows:

java.applet.AppletContext ctx = MyApplet.get().getAppletContext();

FYI: MyApplet extends JApplet and has a private instance of itself which it returns with the public get() method. And no, it doesn't return null.

Thanks for your help in advance...

[589 byte] By [gsoysal] at [2007-9-26 3:34:08]
# 1

I found the problem myself.

If you are using a structure like mine where you have the applet instance be a private member of the applet class, and call it with a getter method, you can't just get the appletContext from the returned instance variable. You actually have to get the applet context in the init() method of the applet, and store it as a member variable, and create a getter method for it as well.

gsoysal at 2007-6-29 12:03:18 > top of Java-index,Archived Forums,Swing...