NullPointerException Error

Sorry about the double post

Page 1 of 1

2 Replies - 462 Views - Last Post: 10 February 2009 - 10:46 AM Rate Topic: -----

#1 DanielRT  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 09-February 09

NullPointerException Error

Post icon  Posted 10 February 2009 - 10:28 AM

I'm getting a NullPointerException error at line 76 (see below) of my code.

I'm guessing it's got something to do with the arrays I'm using (/arrays in general), that I'm not allowed to do.
Can't figure out what.


line 76:
		timeBinary[0] = "	"; <--- Line 76
		timeBinary[1] = "   ";
		timeBinary[2] = "   ";
		timeBinary[3] = "  ";
		timeBinary[4] = "  ";
		timeBinary[5] = "  ";
		timeBinary[6] = "  ";
		timeBinary[7] = " ";
		timeBinary[8] = "   ";
		timeBinary[9] = "  ";
		timeBinary[10] = "eror";



whole code:
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;

public class binaryClock extends JFrame {
	
	final int FRAME_WIDTH = 100;
	final int FRAME_HEIGHT = 100;
	
	final int HOURPANEL_9_WIDTH = 2;
	final int HOURPANEL_9_HEIGHT = 75;
	final int HOURPANEL_9_LOCATION_X = 10;
	final int HOURPANEL_9_LOCATION_Y = 5;
	
	final int HOURPANEL_6_WIDTH = 2;
	final int HOURPANEL_6_HEIGHT = 75;
	final int HOURPANEL_6_LOCATION_X = 20;
	final int HOURPANEL_6_LOCATION_Y = 5;
	
	final int MINPANEL_9_WIDTH = 2;
	final int MINPANEL_9_HEIGHT = 75;
	final int MINPANEL_9_LOCATION_X = 40;
	final int MINPANEL_9_LOCATION_Y = 5;
	
	final int MINPANEL_6_WIDTH = 2;
	final int MINPANEL_6_HEIGHT = 75;
	final int MINPANEL_6_LOCATION_X = 50;
	final int MINPANEL_6_LOCATION_Y = 5;
	
	final int SECPANEL_9_WIDTH = 2;
	final int SECPANEL_9_HEIGHT = 75;
	final int SECPANEL_9_LOCATION_X = 70;
	final int SECPANEL_9_LOCATION_Y = 5;
	
	final int SECPANEL_6_WIDTH = 2;
	final int SECPANEL_6_HEIGHT = 75;
	final int SECPANEL_6_LOCATION_X = 80;
	final int SECPANEL_6_LOCATION_Y = 5;
	
	public static void main (String[] args) throws InterruptedException
	{
		new binaryClock ();
	}
	
	JPanel panelHour9 = new JPanel ();
	JPanel panelHour6 = new JPanel ();
	JPanel panelMin9 = new JPanel ();
	JPanel panelMin6 = new JPanel ();
	JPanel panelSec9 = new JPanel ();
	JPanel panelSec6 = new JPanel ();
	
	JLabel clockHour9 = new JLabel ();
	JLabel clockHour6 = new JLabel ();
	JLabel clockMin9 = new JLabel ();
	JLabel clockMin6 = new JLabel ();
	JLabel clockSec9 = new JLabel ();
	JLabel clockSec6 = new JLabel ();
	
	String timeBinary[];
	String timeHour9;
	String timeHour6;
	String timeMin9;
	String timeMin6;
	String timeSec9;
	String timeSec6;
	
	int timeBH9;
	int timeBH6;
	int timeBM9;
	int timeBM6;
	int timeBS9;
	int timeBS6;
	
	public binaryClock () throws InterruptedException
	{
		timeBinary[0] = "	";
		timeBinary[1] = "   ";
		timeBinary[2] = "   ";
		timeBinary[3] = "  ";
		timeBinary[4] = "  ";
		timeBinary[5] = "  ";
		timeBinary[6] = "  ";
		timeBinary[7] = " ";
		timeBinary[8] = "   ";
		timeBinary[9] = "  ";
		timeBinary[10] = "eror";
		
		this.setLayout (null);
		
		panelHour9.setSize (HOURPANEL_9_WIDTH, HOURPANEL_9_HEIGHT);
		panelHour6.setSize (HOURPANEL_6_WIDTH, HOURPANEL_6_HEIGHT);
		panelMin9.setSize (MINPANEL_9_WIDTH, MINPANEL_9_HEIGHT);
		panelMin6.setSize (MINPANEL_6_WIDTH, MINPANEL_6_HEIGHT);
		panelSec9.setSize (SECPANEL_9_WIDTH, SECPANEL_9_HEIGHT);
		panelSec6.setSize (SECPANEL_6_WIDTH, SECPANEL_6_HEIGHT);
		this.setSize (FRAME_WIDTH, FRAME_HEIGHT);
		
		panelHour9.setLocation (HOURPANEL_9_LOCATION_X, HOURPANEL_9_LOCATION_Y);
		panelHour6.setLocation (HOURPANEL_6_LOCATION_X, HOURPANEL_6_LOCATION_Y);
		panelMin9.setLocation (MINPANEL_9_LOCATION_X, MINPANEL_9_LOCATION_Y);
		panelMin6.setLocation (MINPANEL_6_LOCATION_X, MINPANEL_6_LOCATION_Y);
		panelSec9.setLocation (SECPANEL_9_LOCATION_X, SECPANEL_9_LOCATION_Y);
		panelSec6.setLocation (SECPANEL_6_LOCATION_X, SECPANEL_6_LOCATION_Y);
		this.setLocationRelativeTo (null);
		
		panelHour9.add (clockHour9);
		panelHour6.add (clockHour6);
		panelMin9.add (clockMin9);
		panelMin6.add (clockMin6);
		panelSec9.add (clockSec9);
		panelSec6.add (clockSec6);
		this.add (panelHour6);
		this.add (panelHour9);
		this.add (panelMin6);
		this.add (panelMin9);
		this.add (panelSec6);
		this.add (panelSec9);
		
		this.setTitle ("Binary Clock");
		this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
		this.setVisible (true);
		
		while (true) {
			timeSec9 = timeBinary[timeBS9++];
			
			Thread.sleep (1000);
			
			if (timeBS9 == 10) {
				timeSec6 = timeBinary[timeBS6++];
				timeBH9 = 0;
				
				if (timeBM9 == 10) {
					timeMin9 = timeBinary[timeBM9++];
					timeBS6 = 0;
					
					if (timeBM6 == 6) {
						timeMin6 = timeBinary[timeBM6++];
						timeBM9 = 0;
					
						if (timeBM9 == 9) {
							timeHour9 = timeBinary[timeBH9++];
							timeBM6 = 0;
						
							if (timeBH6 == 6) {
								timeHour6 = timeBinary[timeBH6++];
								timeBH9 = 0;
								
								if (timeBH6 == 10) {
									timeBH9 = 0;
									timeBH6 = 0;
									timeBM9 = 0;
									timeBM6 = 0;
									timeBS9 = 0;
									timeBS6 = 0;
									
									this.setTitle ("There's no way you had this playing for 10 houres");
									break;
								}
							}
						}
					}
				}
			}
			clockHour9.setText (timeHour9);
			clockHour6.setText (timeHour6);
			clockMin9.setText (timeMin9);
			clockMin6.setText (timeMin6);
			clockSec9.setText (timeSec9);
			clockSec6.setText (timeSec6);
		}
	}
}



Sorry about the double post

This post has been edited by DanielRT: 10 February 2009 - 10:31 AM


Is This A Good Question/Topic? 0
  • +

Replies To: NullPointerException Error

#2 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 520
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: NullPointerException Error

Posted 10 February 2009 - 10:41 AM

You haven't initialized the array.

String binaryTime[];

// change the above...to this.

String binaryTime[] = new String[11];


That will fix your problem. Just edit the line where you declared the array.

Happy coding! :D
Was This Post Helpful? 0
  • +
  • -

#3 DanielRT  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 09-February 09

Re: NullPointerException Error

Posted 10 February 2009 - 10:46 AM

It works.
Thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1