Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get Nullpointerexception when drawing a created(uncreated) image

Status
Not open for further replies.

zappsweden

Programmer
Aug 29, 2001
16
SE
the following code gives me Nullpointerexception when trying to drawImage(bi, 0, 0, this)
I am trying to get Image to work before I doubleBuffer it but my createImage or getImage doesn't work(I tried both).
Which one is preferred anyway?
YES, i have put the test.gif in the same directory as Trackcanvas(both in sources and classes library). I even tried a jpg file. I also tried adding the jpg/gif to my project(in JBuilder4) and it actually appeared in my class library also, but no difference.

package f13000.menu.race;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.Graphics;
import f13000.game.RaceWeekend;
import java.awt.image.BufferedImage;
import java.awt.Graphics2D;

/**
* Title:
* Description:
* Copyright: Copyright (c) 2001
* Company:
* @author
* @version 1.0
*/



public class TrackCanvas extends Canvas {
RaceWeekend raceWeekend;
/*Buffered*/Image bi;
Graphics2D big;
boolean firstTime=true;
public TrackCanvas(RaceWeekend r) {
raceWeekend=r;
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setBackground(Color.green);
this.setEnabled(true);
this.setForeground(Color.blue);
}

public void paint(Graphics g) {
//if(this.firstTime==true)
{
bi = Toolkit.getDefaultToolkit().getImage("test.gif");
//big = bi.createGraphics();

}
//if(this.firstTime==true) this.firstTime=false;
big.drawImage(bi, 0, 0, this);
}
}
 
how big is your image, it may be defaulting to a small size hence why you can't see it? try displaying the size and see what it says.
bruce21.jpg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top