L
Linus Norton
i have an applet Game which has a Player class which in turn has an
Animation class. the Animation class loads the image into an array using
getImage and can then retrieve the current Image.
the player class has a method animate which gets the current Image from the
animation class and returns it to the Game class.
but for some reason when i call g.drawImage(player1.animate(),50,50,this) i
get an error at run time:
java.lang.NullPointerException
at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:50)
at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:736)
at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:2755)
at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:2745)
at Game.Game.paint(Game.java:46)
at sun.awt.RepaintArea.paint(RepaintArea.java:177)
at
sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:260)
at java.awt.Component.dispatchEventImpl(Component.java:3678)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.ja
va:201)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java
:151)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
but when i create the image in the Game class using:
getImage(codeBase(),("Game/graphics/animations/Default/0.jpg"))
it works. ive checked that the paths it uses are the same so i cant really
think why its doing it. anyway thanks for any help
Linus
Animation class. the Animation class loads the image into an array using
getImage and can then retrieve the current Image.
the player class has a method animate which gets the current Image from the
animation class and returns it to the Game class.
but for some reason when i call g.drawImage(player1.animate(),50,50,this) i
get an error at run time:
java.lang.NullPointerException
at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:50)
at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:736)
at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:2755)
at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:2745)
at Game.Game.paint(Game.java:46)
at sun.awt.RepaintArea.paint(RepaintArea.java:177)
at
sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:260)
at java.awt.Component.dispatchEventImpl(Component.java:3678)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.ja
va:201)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java
:151)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
but when i create the image in the Game class using:
getImage(codeBase(),("Game/graphics/animations/Default/0.jpg"))
it works. ive checked that the paths it uses are the same so i cant really
think why its doing it. anyway thanks for any help
Linus