Re: newbie: j2me - NullPointerException problems



Jeff wrote:
******** chemistry class ***********
package com.test;

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

public class chemistry extends MIDlet implements CommandListener
{
 private static Display display;
// snip
 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
.



Relevant Pages

  • RE: How to Reference a Property in a Linked Library - I think
    ... Just getting the XY Scatter chart to display properly was a near ... I have only used the Object Browser for the standard reference ... and do not know how to reference additional libraries ...
    (microsoft.public.access.modulesdaovba)
  • Re: referencing columns from list box?
    ... without the reference to Column) ... Doug Steele, Microsoft Access MVP ... Is there a way to get Me.MyTextbox to display ... The control source is Forest. ...
    (microsoft.public.access.formscoding)
  • Re: Adding new entry with specific value
    ... > Now I just want to be able to display the value of TOP_1 query as a ... > reference. ...
    (microsoft.public.access.forms)
  • Re: Are you as polite and diplomatic as COBOL?...
    ... The "balloon" approach might be a good option for some, ... Just do a quick reference in the N/E help file on those ... > decimals or without decimals. ... > enter 1234 and I display 1.234 ...
    (comp.lang.cobol)
  • Re: Display values set in a range??
    ... your reference argument is invalid as you don't have a letter ... when I'm attempting to display something within a particular ... cell from another cell, I end up using the INDIRECT, and ADDRESS functions ... column starting with the row that the MATCH function returned as a valid row ...
    (microsoft.public.excel.worksheet.functions)