Please help!!

I am creating this midlet (non vital coding excluded) but I feel like a noob!


here is the code:

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.lang.*;

public class MainMenu
	extends MIDlet
	implements CommandListener
{
	public Display mDisplay;
	private List mlstMainMenu;
	private Calculator mobjCalculator;
	private Command mcmdOK;



	public MainMenu()
	{

		//create Items
		String[] strMenuItems = {"Calculator", "Other Stuff"};
		mlstMainMenu = new List("Main Menu", List.IMPLICIT, strMenuItems, null);


		//create commands
		mcmdOK = new Command("Ok", Command.SCREEN, 0);
		Command cmdExit = new Command("Exit", Command.EXIT, 1);

		//add commands to the form
		mlstMainMenu.addCommand(mcmdOK);
		mlstMainMenu.addCommand(cmdExit);
		mlstMainMenu.setCommandListener(this);

		mobjCalculator = new Calculator(mDisplay);


	}


	public void startApp()
	{
		if (mDisplay == null) mDisplay = Display.getDisplay(this);
		mDisplay.setCurrent(mlstMainMenu);

	}

	public void pauseApp() { }
	public void destroyApp(boolean unconditional) { }

	public void commandAction(Command c, Displayable s)
	{
		if (c.getCommandType() == Command.EXIT)
			notifyDestroyed();

		else if(c == List.SELECT_COMMAND || c == mcmdOK)
		{
			int index = mlstMainMenu.getSelectedIndex();
			if (mlstMainMenu.getString(index).equals("Calculator"))
			{
				mDisplay.setCurrent(mobjCalculator.ShowCalculator(mDisplay.getCurrent()));
				//mlstMainMenu.set(index, "WORKED!", null);
			}
		}


	}
}

public class Calculator
	implements CommandListener
{
	private Form mfrmCalc;
	private Command mcmdClear, mcmdCalculate, mcmdMainMenu;
	private StringItem mstrPoints;
	private Spacer mSpacer;
	private Display mDisplay;
	private Displayable mParent;


	public Calculator(Display objDisplay)
	{
		mDisplay = objDisplay;

		//create forms
		mfrmCalc = new Form("Total Points:  ");


		//create commands
		mcmdClear = new Command("Clear", Command.SCREEN, 1);
		mcmdCalculate = new Command("Calc", "Calculate", Command.SCREEN, 0);
		Command cmdExit = new Command("Exit", Command.EXIT, 1);

		//add commands to the form
		mfrmCalc.addCommand(mcmdClear);
		mfrmCalc.addCommand(mcmdCalculate);
		mfrmCalc.addCommand(cmdExit);

		mfrmCalc.setCommandListener(this);

	}

	public Form ShowThisForm(Displayable objParent)
	{
		mParent = objParent;
		//mDisplay.setCurrent(mfrmCalc);
		return mfrmCalc;
	}


	public void commandAction(Command c, Displayable s)
	{
		if (c.getCommandType() == Command.EXIT)
		{
			try
			{
				mDisplay.setCurrent(mParent);
			}		catch (NullPointerException npe)
			{
				String strTitle =  mParent.getTitle();
				mfrmCalc.setTitle(strTitle);

			}	
		}

	}
}

This works perfectly to open the calculator form and the functionality on the calculator works perfectly. but once in the calculator form and the Exit command is clicked, I get NullPointerException error. Please help!

the ShowThis Form method should be named ShowCalculator. I changed it for posting purposes

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.