This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes null pointer exception... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "null pointer exception..." Watch "null pointer exception..." New topic
Author

null pointer exception...

Jeffrey Chu
Greenhorn

Joined: May 01, 2005
Posts: 10



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 ]

I'm sorry if i break any rules, im new, please bear with me while I learn the rules.
K Riaz
Ranch Hand

Joined: Jan 08, 2005
Posts: 375


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

Joined: Jan 08, 2005
Posts: 375
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

Joined: May 01, 2005
Posts: 10
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

Joined: Dec 06, 2001
Posts: 3061
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


Java API Documentation
The Java Tutorial
Jeffrey Chu
Greenhorn

Joined: May 01, 2005
Posts: 10
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....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: null pointer exception...
 
Similar Threads
Can I use repaint() on a JFrame?
missing components
Urgent!!! Image Arrays, ImagePanel, Loops
How to add new tabs from JMenu
Cannot Make second card panel to show