| | |
Multi class multi form j2me app getting NullPointerException
![]() |
•
•
Join Date: Sep 2007
Posts: 2
Reputation:
Solved Threads: 0
Please help!!
I am creating this midlet (non vital coding excluded) but I feel like a noob!
here is the code:
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!
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!
Last edited by chef.boyardy; Sep 11th, 2007 at 9:55 pm.
![]() |
Similar Threads
- passing values of Select box from JSP to Action class thru form Bean (JSP)
- What is the difference between simple form & MDI form? (Visual Basic 4 / 5 / 6)
- Need Help Regarding MultiThreading (ASP.NET)
- Java Null Pointer Exception (Java)
- Image background in J2ME form (Java)
- Using Microsoft Excel 10.0 Libary Object -Dang .dlls (C#)
- form validation_valkue retaining and changing the color of the labe not entered (HTML and CSS)
- please someone help me urgent (C++)
- Form not sending email (PHP)
Other Threads in the Java Forum
- Previous Thread: Need help with SQL embedded in Java
- Next Thread: Else If statement again. ~.~
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary blackberry block bluetooth character chat class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game givemetehcodez graphics gui html ide image integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loops mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing test textfields threads time title tree tutorial-sample ubuntu update windows working





