私は単純なゲームを書いています。私は最初の3つのクラスを持っています:それに敬意を表するすべてのものを扱うボール、「ボール」の配列から作られた第2のゲーム、そして最後はMAINスレッドを含むウィンドウです。Java - ダブルバッファリングNullPointerException
window.paintはゲームシーンのグラフィックスを受け取るためにgame.drawを呼び出します。ゲームオブジェクトはそれを二重にバッファリングしてImageオブジェクトをPlayerのボール位置(まだ実装されていません)に移動できるようにします。
私はImageオブジェクトを作成していますが、これはnullに初期化されているので、NullPointerExceptionが発生します。ここで
は絵画を処理するメソッドのソースです:
public class MyWindow extends JFrame {
//...the other code
public void paint(Graphics g){
thegame.draw();
repaint();
}
}
public class Game extends JFrame implements Runnable {
ball[] cellmap;
//...the other code
public void draw(){
Image GameImage = createImage(800,800);
Graphics GameGraphics = GameImage.getGraphics();
for(int i = 0;i<cellmap.length;i++)
cellmap[i].draw(GameGraphics);
g.drawImage(GameImage, 0, 0, this);
}
}
public class Ball extends JFrame {
//...the other code
public void draw(Graphics g){
g.setColor(Color.red);
g.fillOval((int)(this.x+this.radious),(int)(this.y+this.radious),
(int)this.radious,(int)this.radious);
}
}
を描くアニメーション化したい場合は、実際の変数のクラスとUpperCamelCaseためlowerCamelCaseを使用していない私に教えてください。 –
おそらく関連しています:http://stackoverflow.com/questions/1541845/problems-with-createimageint-width-int-height –
このコードは、第2の「JFrame」が導入され次第、間違っています。 !もっと早く助けを求めるには、[SSCCE](http://sscce.org/)を投稿してください。 –