Results 1 to 3 of 3
  1. #1
    lawlawlaw is offline Member
    Join Date
    Jan 2012
    Posts
    1
    Rep Power
    0

    Default Problem about Black Screen

    The code cannot run in Netbean,even in cmd with Exception
    Exception in thread "main" java.lang.NullPointerException
    at XO.gameStartup(XO.java:74)
    at XO.init(XO.java:57)
    at XO.<init>(XO.java:38)
    at XO.main(XO.java:84)
    I dun know why and please give me a help. Thanks.

    import java.util.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.awt.image.*;
    import java.net.*;
    import java.lang.System;

    public class XO extends JFrame implements Runnable,KeyListener{
    private Image[] img;
    public BufferedImage backbuffer;
    public Graphics2D g2d;
    Thread t;

    //definition
    final int STATE_NOTHING = 0;
    final int STATE_CROSS = 1;
    final int STATE_CIRCLE = 2;
    int[] metric;
    public XO(){

    metric = new int[9];
    setSize(600,600);
    setVisible(true);
    backbuffer = new BufferedImage(600,600,BufferedImage.TYPE_INT_RGB);
    g2d = backbuffer.createGraphics();
    addKeyListener(this);
    init();
    gameStartup();
    Thread t = new Thread(this);
    }

    public void run(){
    while(t==Thread.currentThread()){
    try{
    Thread.sleep(1000/30);
    }catch(InterruptedException e){e.printStackTrace();}
    update();
    repaint();
    }
    }
    public void update(){
    //g2d.drawString("fassssssssssssss",50,50);
    g2d.drawImage(img[0], 50,50,this);
    }
    public void init(){
    gameStartup();
    }
    public void paint(Graphics g){
    g.drawImage(backbuffer,0,0,this);
    }
    private URL getURL(String fname){
    URL url = null;
    try{
    url = this.getClass().getResource(fname);
    }catch(Exception e){}
    return url;
    }
    public void load(Image img,String fname){
    Toolkit tk = Toolkit.getDefaultToolkit();
    img = tk.getImage(getURL(fname));
    }
    public void gameStartup(){
    load(img[0],"cross.png");
    load(img[1],"circle.png");
    load(img[2],"nothing.png");
    }
    public void keyTyped(KeyEvent k){}
    public void keyPressed(KeyEvent k){
    }
    public void keyReleased(KeyEvent k){
    }
    public static void main(String[] argv){
    new XO();
    }

    }

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default Re: Problem about Black Screen

    img[] is null.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: Problem about Black Screen

    Not a Java2D problem. Moving to 'New to Java'

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Problem with splash screen
    By frintocf in forum AWT / Swing
    Replies: 1
    Last Post: 09-07-2011, 12:42 AM
  2. Java ME recall screen problem
    By kev670 in forum New To Java
    Replies: 5
    Last Post: 03-23-2011, 01:20 AM
  3. Splash screen problem
    By goklien in forum NetBeans
    Replies: 1
    Last Post: 03-22-2011, 09:30 AM
  4. screen resolution problem
    By prabhug1987 in forum Advanced Java
    Replies: 1
    Last Post: 10-15-2010, 08:01 PM
  5. Full Screen Frame Resolution Problem
    By Krooger in forum AWT / Swing
    Replies: 2
    Last Post: 11-25-2009, 12:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •