J
Jeff
Hey
J2ME Wireless Toolkit 2.2
JDK 5
When I run this midlet (see source code below) it crashes when I select the
"Molar Converter" menu item
This is the crash message I get:
java.lang.NullPointerException
at com.test.chemistry.commandAction(+39)
at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(+282)
at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(+10)
at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(+68)
at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(+47)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+250)
I'm not sure why I get this message when selecting the "Molar Converter",
I've been debugging and as far as I know the MolarConverterForm class is
constructed okay (After MolarConverterForm is constructed I execute one of
it's public methods from the constructor of chemistry, and the return value
is okay)
I would be very thankful if you could give me some tips about what I'm doing
wrong here!
One other thing!
You see from the source code that I use different forms, and one form I've
extended.... Is this a good J2ME technique? I'm doing this because I want to
learn how to interact with multiple forms within a midlet.... Maybe you have
link to webpage demonstrated how to interact with multiple forms within
J2ME.. Then please give it to me
Of course all this code is done because I want to learn how to programming
in J2ME, I don't want to be a newbie
...
Best Regards
Jeff
******** chemistry class ***********
package com.test;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class chemistry extends MIDlet implements CommandListener
{
private static Display display;
private Command exitCommand = new Command("Exit", Command.EXIT, 99);
private Command molarCommand = new Command("Molar Converter",
Command.SCREEN, 1);
private Command addElementCommand = new Command("Add Element",
Command.SCREEN, 1);
private Form form;
private StringItem lblWelcome;
private StringItem lblInfo;
private MolarConverterForm molarForm;
public chemistry()
{
Display display = Display.getDisplay(this);
form = new Form("Chemistry");
molarForm = new MolarConverterForm("Molar Converter");
//Add GUI elements:
lblInfo = new StringItem(molarForm.formDebug(), null);
lblInfo.setLayout(Item.LAYOUT_CENTER);
form.append(lblInfo);
//Add commands
form.addCommand(exitCommand);
form.addCommand(addElementCommand);
form.addCommand(molarCommand);
display.setCurrent(form);
form.setCommandListener(this);
}
public void startApp()
{
//Display display = Display.getDisplay(this);
//display.setCurrent(form);
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
}
public void commandAction(Command c, Displayable s) {
if (c == exitCommand)
{
try
{
destroyApp(false);
notifyDestroyed();
}
catch (Exception ex)
{
}
}
else if (c == molarCommand)
{
//try
//{
display.setCurrent(molarForm);
//}
//catch (Exception ex)
//{
//}
}
}
}
************* MolarConverterForm **************
package com.test;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class MolarConverterForm extends Form
{
private TextField molarValue;
private String formConstructed ="";
public MolarConverterForm(String title)
{
super(title);
formConstructed = title;
molarValue = new TextField("Molar Value = ", "", 10, TextField.ANY);
append(molarValue);
}
public String formDebug()
{
return formConstructed;
}
}
J2ME Wireless Toolkit 2.2
JDK 5
When I run this midlet (see source code below) it crashes when I select the
"Molar Converter" menu item
This is the crash message I get:
java.lang.NullPointerException
at com.test.chemistry.commandAction(+39)
at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(+282)
at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(+10)
at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(+68)
at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(+47)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+250)
I'm not sure why I get this message when selecting the "Molar Converter",
I've been debugging and as far as I know the MolarConverterForm class is
constructed okay (After MolarConverterForm is constructed I execute one of
it's public methods from the constructor of chemistry, and the return value
is okay)
I would be very thankful if you could give me some tips about what I'm doing
wrong here!
One other thing!
You see from the source code that I use different forms, and one form I've
extended.... Is this a good J2ME technique? I'm doing this because I want to
learn how to interact with multiple forms within a midlet.... Maybe you have
link to webpage demonstrated how to interact with multiple forms within
J2ME.. Then please give it to me
Of course all this code is done because I want to learn how to programming
in J2ME, I don't want to be a newbie
Best Regards
Jeff
******** chemistry class ***********
package com.test;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class chemistry extends MIDlet implements CommandListener
{
private static Display display;
private Command exitCommand = new Command("Exit", Command.EXIT, 99);
private Command molarCommand = new Command("Molar Converter",
Command.SCREEN, 1);
private Command addElementCommand = new Command("Add Element",
Command.SCREEN, 1);
private Form form;
private StringItem lblWelcome;
private StringItem lblInfo;
private MolarConverterForm molarForm;
public chemistry()
{
Display display = Display.getDisplay(this);
form = new Form("Chemistry");
molarForm = new MolarConverterForm("Molar Converter");
//Add GUI elements:
lblInfo = new StringItem(molarForm.formDebug(), null);
lblInfo.setLayout(Item.LAYOUT_CENTER);
form.append(lblInfo);
//Add commands
form.addCommand(exitCommand);
form.addCommand(addElementCommand);
form.addCommand(molarCommand);
display.setCurrent(form);
form.setCommandListener(this);
}
public void startApp()
{
//Display display = Display.getDisplay(this);
//display.setCurrent(form);
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
}
public void commandAction(Command c, Displayable s) {
if (c == exitCommand)
{
try
{
destroyApp(false);
notifyDestroyed();
}
catch (Exception ex)
{
}
}
else if (c == molarCommand)
{
//try
//{
display.setCurrent(molarForm);
//}
//catch (Exception ex)
//{
//}
}
}
}
************* MolarConverterForm **************
package com.test;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class MolarConverterForm extends Form
{
private TextField molarValue;
private String formConstructed ="";
public MolarConverterForm(String title)
{
super(title);
formConstructed = title;
molarValue = new TextField("Molar Value = ", "", 10, TextField.ANY);
append(molarValue);
}
public String formDebug()
{
return formConstructed;
}
}