Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

NullPointerException on a Mancala Program

807588Feb 14 2009 — edited Feb 23 2009
Hey all, I'm working on a mancala program for a project. I'm getting the following error:
Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException
	at Board$holeListener_03.actionPerformed(Board.java:129)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)
This is where the error is pointing to:
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import java.awt.Container;
import java.awt.Dimension;

public class Board extends JApplet
{
	private final int APPLET_WIDTH = 720;
	private final int APPLET_HEIGHT = 567;
	private Image board;
	Game mancala = new Game();
	
	int hole = 4;

	JButton[][] bowlBut = new JButton[2][6];
	JButton[] largeBowl = new JButton[2];

	public void init()
	{		
		Container cp = getContentPane();
		cp.repaint();
		for (int i = 0; i < 2; i++)
		{
			for(int j=0; j<6; j++)
			{
				bowlBut[i][j] = new JButton("4");				
				cp.add(bowlBut[i][j]);
			}
		}
		
		bowlBut[0][3].addActionListener (new holeListener_03());
		
		for (int i = 0; i < 2; i++)
		{
			largeBowl[i] = new JButton("0");
			cp.add(largeBowl);
}
cp.repaint();

board = getImage (getDocumentBase(), "board.jpg");
setSize (APPLET_WIDTH, APPLET_HEIGHT);

cp.setBackground (Color.white);
cp.setLayout (null);

Dimension size = bowlBut[0][0].getPreferredSize();
bowlBut[0][0].setBounds(112, 285, 50, size.height + 10);
bowlBut[0][1].setBounds(202, 285, 50, size.height + 10);
bowlBut[0][2].setBounds(290, 285, 50, size.height + 10);
bowlBut[0][3].setBounds(385, 285, 50, size.height + 10);
bowlBut[0][4].setBounds(473, 285, 50, size.height + 10);
bowlBut[0][5].setBounds(560, 285, 50, size.height + 10);

bowlBut[1][0].setBounds(112, 398, 50, size.height + 10);
bowlBut[1][1].setBounds(202, 398, 50, size.height + 10);
bowlBut[1][2].setBounds(290, 398, 50, size.height + 10);
bowlBut[1][3].setBounds(385, 398, 50, size.height + 10);
bowlBut[1][4].setBounds(473, 398, 50, size.height + 10);
bowlBut[1][5].setBounds(562, 398, 50, size.height + 10);
//to change button text: button.setText("This is a test.")



largeBowl[0].setBounds(25, 325, 50, size.height + 10);
largeBowl[1].setBounds(650, 325, 50, size.height + 10);
cp.repaint();
}

public void drawPictures(int size, Graphics page)
{
page.drawImage (board, 0, 0, 720, 567, this);
}

public void paint (Graphics page)
{
drawPictures (APPLET_WIDTH, page);
}




public class holeListener_03 implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
System.out.println("03");
mancala.distributeStones(3,mancala.gameBowl[0][3].getQuantity());
refreshBowls();
}
}


private void refreshBowls()
{
for (int i = 0; i < 2; i++)
{
for(int j=0; j<6; j++)
{
bowlBut[i][j].setText(""+mancala.gameBowl[i][j].getQuantity());
}
}
}
}
I can post other classes if I need to. Just let me know.

Thanks in advance.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 23 2009
Added on Feb 14 2009
10 comments
107 views