I am not sure what is wrong here. createImage is always returning null. What's the usage of createImage ? class Test extends Panel{ Image img; public Test(){ img = createImage(100,100); // After this, img is always null. } }
Could you tell us which package contains the createImage()? In java.awt.Graphics, we have drawImage(). Not sure whether createImage method is a built-in method... If it is user defined, then createImage() should create an Image and return it to the caller. Otherwise, the object img will be null... Uma
Before we call createImage(), it must have been realized, i.e., actually displayed. The addNotify() of Component sets the component ready for display. After you call super.addNotify(), the component is realized. Now modify your code like this and test... class Test extends Panel{ Image img; public void addNotify(){ super.addNotify(); img = createImage(100,100); // After this, img is always null. if(img != null) System.out.println( "not null" ); else System.out.println( "null" ); } }
If you are using a rototiller, you are doing it wrong. Even on this tiny ad:
a bit of art, as a gift, that will fit in a stocking