NullPointerException

I am learning Java and I have been working on a problem for about 20 hours but I continue to get a NullPointerException. I do not believe it makes sense after reviewing Sun’s Java Tutorial and my text books. I am trying to add two numbers from text fields as a simple calculator. I have programmed (multiply, divide and subtract) to visually read that the actions are occurring; however, adding two numbers is causing the exception. My code is attached.
Thanks for any assistance.

import java.awt.;
import java.awt.event.
;
import java.text.NumberFormat;

import javax.swing.*;

public class FinalCalculator {
public static void main(String[]args){
CalculatorFrame frame = new CalculatorFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}

class CalculatorFrame extends JFrame{
public CalculatorFrame(){
setTitle(“Brooks Calculator”);
Container contentPane = getContentPane();
CalculatorPanel panel = new CalculatorPanel();
contentPane.add(panel);
pack();
}
}

class CalculatorPanel extends JPanel{
private JLabel display;
private JPanel panel;
private double result;
private String lastCommand;
private boolean start;
private JFormattedTextField inputField1;
private JFormattedTextField inputField2;

public CalculatorPanel(){
	setLayout(new BorderLayout());
	
	result = 0;
	lastCommand = "=";
	start = true;
	
	display = new JLabel("0");
	add(display, BorderLayout.NORTH);

// ActionListener insert = new InsertAction();
ActionListener command = new CommandAction();

	panel = new JPanel();
	panel.setLayout(new GridLayout(4, 4));
	
	addButton("Division", command);
	addButton("Add", command);
	addButton("Multiply", command);
	addButton("Subtract", command);
	
	add(panel, BorderLayout.CENTER);
	
	JFormattedTextField inputField1 = new JFormattedTextField(
		NumberFormat.getIntegerInstance());
	JFormattedTextField inputField2 = new JFormattedTextField();
	
	inputField1.setText("2");
	inputField2.setText("3");
	add(inputField1, BorderLayout.EAST);
	add(inputField2, BorderLayout.WEST);	
}

private void addButton (String label, ActionListener listener){
	JButton button = new JButton(label);
	button.addActionListener(listener);
	panel.add(button);
}
	
private class CommandAction implements ActionListener{
	public void actionPerformed(ActionEvent evt){
		String command = evt.getActionCommand();

// double x = Double.parseDouble(inputField1.getText());
if (start)
{
if (command.equals(“Add”))
{
display.setText(Double.toString(
Double.parseDouble(inputField1.getText())+
Double.parseDouble(inputField2.getText())));
start = false;
}
if (command.equals(“Division”)){

				display.setText(command);
			}
			if (command.equals("Subtract")){
				display.setText(command);
			}else{
				display.setText("Multiply");
			}
		}
	}
}

}

Dear scbrooks,

Both inputField1 and inputField2 are null. During the construction of UI, you declared local variables inputField1 and inputField2 which overrides the attributes with the same names. By the way, I suggest you add a println statement to print the variables that may caused the null pointer exception, which would make debugging easier.

Regards,

Antony.

I keep on getting the error where my constructor TicToePanel cannot be recognized. It says that it cannot resolve the symbol. I do have a TicTacToePanel and it is saved in the same folder so I do not know what to do. Can you please help me witht this?

import java.awt.;
import javax.swing.
;
import java.awt.event.*;

public class TicTacToe extends JFrame{

private JButton[][] frameboard;
private ModelBoard ttm;

private TicTacToePanel b1;
private TicTacToePanel b2;
private TicTacToePanel b3;
private TicTacToePanel b4;
private TicTacToePanel b5;
private TicTacToePanel b6;
private TicTacToePanel b7;
private TicTacToePanel b8;
private TicTacToePanel b9;

public TicTacToe () {

frameboard = new JButton[3][3];
ttm = new ModelBoard();
JPanel panel = new JPanel();

panel.setLayout(new GridLayout (3,3));
panel.setPreferredSize (new Dimension (300, 75));
panel.setBackground (Color.yellow);

b1 = new TicTacToePanel(ttm, 0, 0, this);
b2 = new TicTacToePanel(ttm, 0, 1, this);
b3 = new TicTacToePanel(ttm, 0, 2, this);
b4 = new TicTacToePanel(ttm, 1, 0, this);
b5 = new TicTacToePanel(ttm, 1, 1, this);
b6 = new TicTacToePanel(ttm, 1, 2, this);
b7 = new TicTacToePanel(ttm, 2, 0, this);
b8 = new TicTacToePanel(ttm, 2, 1, this);
b9 = new TicTacToePanel(ttm, 2, 2, this);

panel.add(b1);
panel.add(b2);
panel.add(b3);
panel.add(b4);
panel.add(b5);
panel.add(b6);
panel.add(b7);
panel.add(b8);
panel.add(b9);

getContentPane().add(panel);

} //CLOSES CONSTRUCTOR

public static void main (String args[]) {

TicTacToe frame = new TicTacToe();

// frame.pack();
frame.show();
}

} //CLOSE CLASS

//-----------------------------------------------------------------------------------//

import java.awt.;
import javax.swing.
;
import java.awt.event.*;

public class ModelBoard {

char[][] model;
public static final char X = ‘x’;
public static final char O = ‘o’;
public static final char EMPTY = ’ ';

public ModelBoard() {

model = new char[3][3];
int row;
int col;

for (row = 0; row <3; row++) {
    for (col = 0; col <3; col++) {
	      model[row][col] = 'j';
		}
  }

} // closes contuctor

hard to say, without the class tictactoePanel implementation… is it in the same package? is the construktor in form: ModelBoard,int,int,JFrame ?

hi friend;

    i think u had declared an object but not used .better check it properly.the reason for null pointer exception is that