Re: newbie: j2me - NullPointerException problems
- From: "Darryl L. Pierce" <mcpierce@xxxxxxxxx>
- Date: Tue, 11 Oct 2005 06:40:02 -0400
Jeff wrote:
// snip******** chemistry class *********** package com.test;
import javax.microedition.midlet.*; import javax.microedition.lcdui.*;
public class chemistry extends MIDlet implements CommandListener { private static Display display;
public chemistry() {
Display display = Display.getDisplay(this);
This line right here is creating a *local* (to the constructor) reference to the Display object for the MIDlet. The instance reference is still *uninitialized*.
// snip
public void commandAction(Command c, Displayable s) {
if (c == exitCommand)
{
try
{
destroyApp(false);
This is an unnecessary method call. The lifecycle methods (startApp, pauseApp and destroyApp) are methods invoked by the platform. You should not be invoking them yourself.
// snip
else if (c == molarCommand)
{
//try
//{
display.setCurrent(molarForm);
Since it was never initialized, display is *null*, hence your NPE when this is invoked.
HTH.
-- Darryl L. Pierce <mcpierce@xxxxxxxxx> Homepage: http://mcpierce.multiply.com/ "Bury me next to my wife. Nothing too fancy..." - Ulysses S. Grant .
- References:
- newbie: j2me - NullPointerException problems
- From: Jeff
- newbie: j2me - NullPointerException problems
- Prev by Date: Re: Java running for ever on Linux
- Next by Date: Re: Iterate over Hashmap with JSTL
- Previous by thread: Re: newbie: j2me - NullPointerException problems
- Next by thread: getActualMaximum of Calendar.WEEK_OF_MONTH confusion
- Index(es):
Relevant Pages
|