java - NullPointerException Error on an Image -
i'm working in java , wanted create arraylist of bufferedimages:
arraylist<bufferedimage> anotelist = new arraylist<bufferedimage>();
i want populate arraylist 197 bufferedimages in constructor of drawpanel class.
public drawpanel(){ for(int = 0; < 197; i++){ try { anotelist.add(imageio.read(new file("a.png"))); } catch (ioexception e) { e.printstacktrace(); } } setpreferredsize(new dimension(400, 600)); panelsize=getpreferredsize(); height=(int) panelsize.getheight(); width=(int) panelsize.getwidth(); system.out.printf("%d, %d\n",height,width); loadimage(); }
then, in drawframe class, create object out of drawpanel class called canvas. use canvas here.
/*this checks see if song @ specified time , calls fall method in drawpanel class.*/ public void checkiffall() throws ioexception{ if(song.gettime() / 1000000000 == (jojo.getaarray()[canvas.getai()] /1000000000)){ //system.out.println("a fall"); canvas.fall(canvas.getanotelist().get(canvas.getai() + 1), canvas.getloca()); canvas.setai(canvas.getai()+1); } }
i suspect real issues lie fall method, don't know why.
public void fall(bufferedimage img, location loc) throws ioexception{ if(img != null){ if(img == imageio.read(new file("a.png"))) x = 10; if(img == imageio.read(new file("s.png"))) x = (width-s.getwidth())/2; if(img == imageio.read(new file("d.png"))) x = width-d.getwidth()-20; if(loc.gety()<=height){ system.out.println(img); //offgc.drawimage(img, x, loc.gety(), null); validate(); repaint(); makemove(movepixel(), loc); } } }
i'm getting nullpointerexception when pass image drawimage method, don't know why. array populated, said image wasn't null. what's wrong?! when print out image, got this:
bufferedimage@614c5515: type = 6 colormodel: #pixelbits = 32 numcomponents = 4 color space = java.awt.color.icc_colorspace@1e67b872 transparency = 3 has alpha = true isalphapre = false byteinterleavedraster: width = 50 height = 50 #numdataelements 4 dataoff[0] = 3
does mean anything?
as image not null, can graphics object offgc or loc object call gety() on. try printing out 2 see if null. including full stack trace helpful.
Comments
Post a Comment