Null pointer exception with Java 1.4.2, ok with 1.5

From: Luke (lukeita_at_gawab.com)
Date: 11/27/04


Date: Sat, 27 Nov 2004 12:05:14 GMT

HellO!
I'm working on an image applet, and I've developed an object from
JPanel to show images... this is the simple code:

---
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
class JImagePanel extends JPanel 
{
	private BufferedImage image;
	public void setImage(BufferedImage i)
	{
		image = i;
	}
	public void paintComponent(Graphics g)
	{
		g.drawImage(image,0,0,this);	
	}
}
---
With Java 1.5 works fine, with 1.4.2 I get a Null pointer exception,
which could be the problem?
Thanks
(follows the complete error I see on Java console)
---
java.lang.NullPointerException	at
sun.java2d.pipe.DrawImage.copyImage(Unknown Source)	at
sun.java2d.pipe.DrawImage.copyImage(Unknown Source)	at
sun.java2d.SunGraphics2D.drawImage(Unknown Source)	at
sun.java2d.SunGraphics2D.drawImage(Unknown Source)	at
JImagePanel.paintComponent(JImagePanel.java:16)	at
javax.swing.JComponent.paint(Unknown Source)	at
javax.swing.JComponent.paintChildren(Unknown Source)	at
javax.swing.JComponent.paint(Unknown Source)	at
javax.swing.JComponent.paintChildren(Unknown Source)	at
javax.swing.JComponent.paint(Unknown Source)	at
javax.swing.JComponent.paintChildren(Unknown Source)	at
javax.swing.JComponent.paint(Unknown Source)	at
javax.swing.JLayeredPane.paint(Unknown Source)	at
javax.swing.JComponent.paintChildren(Unknown Source)	at
javax.swing.JComponent.paintWithOffscreenBuffer(Unknown Source)	at
javax.swing.JComponent.paintDoubleBuffered(Unknown Source)	at
javax.swing.JComponent.paint(Unknown Source)	at
java.awt.GraphicsCallback$PaintCallback.run(Unknown Source)	at
sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source)	at
sun.awt.SunGraphicsCallback.runComponents(Unknown Source)	at
java.awt.Container.paint(Unknown Source)	at
sun.awt.RepaintArea.paint(Unknown Source)	at
sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)	at
java.awt.Component.dispatchEventImpl(Unknown Source)	at
java.awt.Container.dispatchEventImpl(Unknown Source)	at
java.awt.Component.dispatchEvent(Unknown Source)	at
java.awt.EventQueue.dispatchEvent(Unknown Source)	at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)	at
java.awt.EventDispatchThread.pumpEvents(Unknown Source)	at
java.awt.EventDispatchThread.run(Unknown Source)


Relevant Pages

  • Re: Newbe, paintComponent problem.
    ... The initial oval, from paintComponent, isn't draw ... private JPanel jPanelbottom = null; ... public void actionPerformed{ ...
    (comp.lang.java.programmer)
  • Re: Cardlayout GUI
    ... their remuneration type and based on this selection a card is called. ... A very good place to start to learn how to use the different layout managers ... JPanel cards; ... public void addComponentToPane{ ...
    (comp.lang.java.programmer)
  • Re: Trying to put a background image in a JFrame
    ... all I get is a tiny square off the window bounds. ... What you need to do is to create a JPanel and set that as the frame's ContentPane. ... public void paintComponent{ ...
    (comp.lang.java.gui)
  • Swing Components not staying where they are dragged to on the JFrame
    ... where the jlabels are added ("destination" jpanel). ... public void actionPerformed(ActionEvent evt) ... public void addComponent ...
    (comp.lang.java.gui)
  • How Do I Set the Focus to a Object?
    ... I had a program running some time back that brought up a <JPanel> ob- ... int height; ... Color clr; ... public void keyReleased ...
    (comp.lang.java.programmer)