Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] NullPointer in App

Started by Sir Sapo Jul 11, 2004 at 2:04 AM 3 replies 500+ views
Original Post
Sir Sapo
Sir Sapo
I have an applet program that loads images and displays them using AWT. It works as an applet but when I put a main method in my applet , and chose to run it as an application, I get an error that says I have a null pointer exception when I try to use getDocumentBase() for my images. Does anyone know why this is happening or do I have to include some code snippets to help get my problem across?
My Current Project Angels 22 (4E5)
etothex
etothex
NullPointerExceptions can occur when you initialize a class to null, but then don't use the new operator or a factory to make a real instance. I imagine you could be doing this:

class FunkeyApplet extends Applet { //...}FunkeyApplet applet = null;//...//function assumes applet = new FunkeyApplet(); has been called, //but it hasn't, so applet == nullapplet.getDocumentBase();


If you're not doing this, then post some snippets of the lines around the call to getDocumentBase()
Sir Sapo
Sir Sapo
Sorry that anonymouse post was me , I forgot to log in
My Current Project Angels 22 (4E5)
Sir Sapo
Sir Sapo
I figured out how to do it,

I made a method called loadImage that returned an ImageIcon with from the specified filename.

Thanks for your help.
My Current Project Angels 22 (4E5)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.