This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

null pointer exception...

 
Jeffrey Chu
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



i've looked at the code my self but i cant see to pin point the problem
[ May 08, 2005: Message edited by: Jeffrey Chu ]
 
K Riaz
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


In Java, you must allocate space for an array using the "new" keyword with its size. In your case, you have an array of type "image", but have not correctly intialized it. Change the offending line to:



Try that.
 
K Riaz
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just one more thing, you will get an ArrayIndexOutOfBounds exception. Array indexes begin from 0, not 1. So use "image[0]=.." and "image[1]=..".
[ May 08, 2005: Message edited by: Kashif Riaz ]
 
Jeffrey Chu
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok i did a rework of my code, but now i get this error...

java.lang.NullPointerException
at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:2721)
at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:2682)
at Scene$DisplayPanel.paintComponent(Scene.java:59)
at javax.swing.JComponent.paint(JComponent.java:808)
at javax.swing.JComponent.paintChildren(JComponent.java:647)
at javax.swing.JComponent.paint(JComponent.java:817)
at javax.swing.JComponent.paintChildren(JComponent.java:647)
at javax.swing.JComponent.paint(JComponent.java:817)
at javax.swing.JLayeredPane.paint(JLayeredPane.java:557)
at javax.swing.JComponent.paintChildren(JComponent.java:647)
at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4794)
at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4740)
at javax.swing.JComponent.paint(JComponent.java:798)
at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21)
at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)
at java.awt.Container.paint(Container.java:1312)
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.java: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)


and my enw code is



 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most of the classes listed in the stack trace you gave are from the Java API. You don't have any direct control over those. However, there is one line that says "Scene$DisplayPanel.paintComponent(Scene.java:59)". This looks promising. It indicates that the problem originated in your Scene.java file on line 59. This is in the paintComponent() method of your DisplayPanel class (which happens to be an inner class of Scene). So which line is #59? I could probably figure it out from the context given in the stack trace, but I thought I'd let you look at it for a minute. If you are still stuck, tell us which line this is referring to and we'll help from there.

Layne
 
Jeffrey Chu
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well i know its refering to g.drawImage ( image[1], 0, 0, 600, 500, this );
but i have that image on my computer.... i have no clue....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic