I am trying to display a black window yet I keep getting null pointer exception on line 72 and 43. This is the base for my video game and I have been using tutorials to help me along since I am new to java. It started as an unreachable code error but I fixed that by return and then this problem immediately came up any help? Code:
package com.tyler99b.platformer.window;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;
public class Game extends Canvas implements Runnable
{
private static final long serialVersionUID = 506346024107270629L;
private boolean running = false;
private Thread thread;
public synchronized void start(){
if(running)
return;
running = true;
thread = new Thread(this);
thread.start();
}
public void run()
{
long lastTime = System.nanoTime();
double amountOfTicks = 60.0;
double ns = 1000000000 / amountOfTicks;
double delta = 0;
long timer = System.currentTimeMillis();
int updates = 0;
int frames = 0;
while(running){
long now = System.nanoTime();
delta += (now - lastTime) / ns;
lastTime = now;
while(delta >= 1){
tick();
updates++;
delta--;
}
render();
frames++;
if(System.currentTimeMillis() - timer > 1000){
timer += 1000;
System.out.println("FPS: " + frames + " TICKS: " + updates);
frames = 0;
updates = 0;
}
}
}
private void tick()
{
}
private void render()
{
BufferStrategy bs = this.getBufferStrategy();
if(bs == null);
{
this.createBufferStrategy(3);
}
Graphics g = bs.getDrawGraphics();
g.setColor(Color.black);
g.fillRect(0,0, getWidth(), getHeight());
g.dispose();
bs.show();
}
public static void main(String args[]){
new Window(800,600, "Platformer Prototype", new Game ());
}
}