How to render Bitmap into Canvas?

How can i fix the java.lang.nullpointerexeption?

  • this is my code: package com.ga.game; import java.util.*; import java.awt.Canvas; import java.awt.Component; import java.awt.Graphics; import java.awt.geom.Area; import java.awt.image.BufferStrategy; import java.awt.image.BufferedImage; import java.awt.image.DataBufferInt; import javax.swing.JFrame; public class display extends Canvas implements Runnable { /** * */ private static final long serialVersionUID = 1L; public static int WIDTH = 800; public static int HEIGHT = 600; public static String title = "My Expert Project!"; public boolean run = true; private Thread thread; public BufferedImage img; public int[] pixel; public ac screen; private int i; private BufferStrategy bs; public display() { screen = new ac() ; img = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB) ; pixel = ((DataBufferInt)img.getRaster().getDataB... ; } public static void main(String args[]) { display game = new display () ; JFrame frame = new JFrame() ; frame.setSize(WIDTH, HEIGHT) ; frame.setResizable(false) ; frame.setVisible(true) ; frame.setTitle(title); frame.setDefaultCloseOperation(JFrame.EX... ; frame.setLocationRelativeTo (null) ; frame.add(game) ; } public void start () { if(run) return; run = true; thread = new Thread(); thread.start(); } public void run() { while(run) render() ; } private void render() { // TODO Auto-generated method stub } public void reder() { BufferStrategy bs = this.getBufferStrategy(); if (bs == null) { createBufferStrategy(3); return; } screen.render (); for(int i=0;i<screen.pixel.length;i++); pixel[i] = screen.pixel[i]; } { Graphics g = bs.getDrawGraphics(); g.drawImage(img, 0, 0, WIDTH, HEIGHT, null) ; g.dispose(); bs.show(); } } whats wrong with it?

  • Answer:

    implements Runnable, KeyListener, MouseListener, MouseMotionListener also add addMouseListener (this); addMouseMotionListener (this); to Main|init

cbat at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

implements Runnable, KeyListener, MouseListener, MouseMotionListener also add addMouseListener (this); addMouseMotionListener (this); to Main|init

Revolut1on1ze

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.