zappsweden
Programmer
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);
}
}
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);
}
}