title: J2ME Back command - returning to previous screen
body: <p><br>I'm stuck trying to figure out how to create a back command to the previous screen.<br>The page I'm trying to return to does not have a form but a List but when I set the <br>'back' command listener to the list it just seems to throw a null pointer exception.</p>
  
  <p>Here is my main class</p>
  
  <pre><code>import java.util.*;
  import javax.microedition.lcdui.*;
  import javax.microedition.midlet.MIDlet;
  
  /**
   * 
   */
  public class CalFrontEnd extends MIDlet implements CommandListener 
  {
      private Display display;
      protected List list = new List("Please Select a Option", List.IMPLICIT);
      private Command select = new Command("Select", Command.SCREEN, 1);
      private Command exit = new Command("Exit", Command.EXIT, 2);
      private Command save = new Command("Save,", Command.SCREEN, 2);
      private DateField calendar;
  
  
      /**
       * 
       */
      public CalFrontEnd() 
      {
          display = Display.getDisplay(this);   
          list.append("Select Date", null);
          list.append("Add Events", null);
          list.append("Remove Events", null);
          list.append("Browse Events", null);
          list.addCommand(select);
          list.addCommand(exit);
          list.setCommandListener(this);
      }
  
  
      /**
       * Start Application
       */
      public void startApp() 
      {
          display.setCurrent(list);
      }
  
  
      /**
       * Pause Application Method
       */
      public void pauseApp() 
      {}
  
  
      /**
       * Destroy Application Method
       */
      public void destroyApp(boolean unconditional)
      {}
  
  
      /**
       * 
       * @param command
       * @param displayable 
       */
      public void commandAction(Command command, Displayable displayable) 
      {
          if (displayable == list) {
              if (command == List.SELECT_COMMAND) {
                  switch (list.getSelectedIndex()) {
                      case 0: // select Date
                          SelectDate myDate = new SelectDate(display);
                          myDate.BuildCalendar();
                          break;
                      case 1: //add Events
                          AddEvents myAEvents = new AddEvents(display);
                          myAEvents.BuildAddEvents();
                          break;
                      case 2: //Remove Events
                          RemoveEvents myREvents = new RemoveEvents(display);
                          myREvents.BuildRemoveEvents();
                          break;
                      case 3: //Browse Events
                          BrowseEvents myBEvents = new BrowseEvents(display);
                          myBEvents.BuildBrowseEvents();
                          break;
                  }
              } else if (command == exit) {
                  destroyApp(false);
                  notifyDestroyed();
              }
          }         
      } 
  }
  </code></pre>
  
  <p>And this is the class which I'm trying to use the back button on</p>
  
  <pre><code>import java.util.*;
  import javax.microedition.lcdui.*;
  
  
  /**
   * 
   */
  public class SelectDate extends CalFrontEnd implements CommandListener 
  {
      private DateField calendar;
      private Form form = new Form("Please Select a Date");
      private Command select = new Command("Select", Command.SCREEN, 1);
      private Command back = new Command("Back", Command.BACK, 2);
      private Command save = new Command("Save,", Command.SCREEN, 2);
      private Display display;
  
  
      /**
       * 
       */
      public SelectDate(Display display)
      {
          this.display = display;
      }
  
  
      /**
       * 
       */
      public void BuildCalendar()
      {
          calendar = new DateField("Date In :", DateField.DATE, TimeZone.getTimeZone("GMT"));
          form.append(calendar);
          form.addCommand(back);
          form.setCommandListener(this);
          display.setCurrent(form);
      }  
  
  
      /**
       * 
       * @param command
       * @param displayable 
       */
      public void commandAction(Command command, Display display)
      {
          if (command == back)
          {
              display.setCurrent(list);
          }
      }
  }
  </code></pre>