title: how to navigate from one page to the other in j2me
body: <p>I am newbie to J2ME. I am trying to navigate from one MIDlet page to the other on the selection of ListItem. But I am getting following error message.</p>
  
  <pre><code>Installing suite from: file:///C:/Users/mohit/Documents/NetBeansProjects/MobileApp1/dist/nbrun8756732879038612272/MobileApp1.jad
  6370272 - ERROR - AMS - 2 - Installation failed:com.sun.midp.midletsuite.MIDletSuiteLockedException
  com.sun.midp.midletsuite.MIDletSuiteLockedException
  at com.sun.midp.midletsuite.MIDletSuiteImpl.lockMIDletSuite(), bci=0
  at com.sun.midp.midletsuite.MIDletSuiteStorage.getMIDletSuite(), bci=12
  at com.sun.midp.installer.Installer.checkPreviousVersion(), bci=60
  at com.sun.midp.installer.Installer.installStep2(), bci=10
  at com.sun.midp.installer.Installer.performInstall(), bci=132
  at com.sun.midp.installer.Installer.resumeInstallation(), bci=7
  at com.sun.midp.installer.MidpInstaller$StartAction.run(), bci=10
  at com.sun.j2me.security.AccessController.doPrivileged(), bci=12
  at com.sun.midp.installer.MidpInstaller$InstallThread.run(), bci=9
  at java.lang.Thread.run(Thread.java:721)
  
  TRACE: &lt;at java.lang.NullPointerException:   0&gt;, Exception caught in Display class
  java.lang.NullPointerException:   0
   - mobileapp1.VisualMIDlet.commandAction(VisualMIDlet.java:180)
  at javax.microedition.lcdui.Display$ChameleonTunnel.callScreenListener(), bci=39
  at com.sun.midp.chameleon.layers.SoftButtonLayer.processCommand(), bci=62
  at com.sun.midp.chameleon.layers.SoftButtonLayer.soft2(), bci=119
  at com.sun.midp.chameleon.layers.SoftButtonLayer.keyInput(), bci=102
  at com.sun.midp.chameleon.CWindow.keyInput(), bci=30
  at javax.microedition.lcdui.Display$DisplayEventConsumerImpl.handleKeyEvent(), bci=43
  at com.sun.midp.lcdui.DisplayEventListener.process(), bci=252
  at com.sun.midp.events.EventQueue.run(), bci=130
  at java.lang.Thread.run(Thread.java:721)
  </code></pre>
  
  <p>I don't know how to handle this one. Can anyone help me out,please?</p>
  
  <pre><code>//VisualMIDlet.java
  package mobileapp1;
  
  import javax.microedition.midlet.*;
  import javax.microedition.lcdui.*;
  import org.netbeans.microedition.lcdui.LoginScreen;
  
  public class VisualMIDlet extends MIDlet implements CommandListener {
  
  private boolean midletPaused = false;
  
  private java.util.Hashtable __previousDisplayables = new java.util.Hashtable();
  private LoginScreen loginScreen;
  private Form FallSem_Home;
  private ChoiceGroup choiceGroup;
  private List stud_homelist;
  private Form WinterSem_Home;
  private Command exit_StudList;
  private Command exitCommand1;
  private Command exitCommand2;
  private Command backCommand;
  private Command ok_StudList;
  private Command okCommand;
  
  private List menu = null;
  private Display display;
  Fall_Sem fall_sem;
  public VisualMIDlet() {
      //fall_sem = new Fall_Sem();
  }
  
  
  private void switchToPreviousDisplayable() {
      Displayable __currentDisplayable = getDisplay().getCurrent();
      if (__currentDisplayable != null) {
          Displayable __nextDisplayable = (Displayable) __previousDisplayables.get(__currentDisplayable);
          if (__nextDisplayable != null) {
              switchDisplayable(null, __nextDisplayable);
          }
      }
  }
  
  private void initialize() {
      // write pre-initialize user code here
  
      // write post-initialize user code here
  }
  
  public void startMIDlet() {
      // write pre-action user code here
      switchDisplayable(null, getLoginScreen());
      // write post-action user code here
  }
  
  public void resumeMIDlet() {
      // write pre-action user code here
  
      // write post-action user code here
  }
  
  public void switchDisplayable(Alert alert, Displayable nextDisplayable) {
      // write pre-switch user code here
      Display display = getDisplay();
      Displayable __currentDisplayable = display.getCurrent();
      if (__currentDisplayable != null &amp;&amp; nextDisplayable != null) {
          __previousDisplayables.put(nextDisplayable, __currentDisplayable);
      }
      if (alert == null) {
          display.setCurrent(nextDisplayable);
      } else {
          display.setCurrent(alert, nextDisplayable);
      }
      // write post-switch user code here
  }
  
  public void commandAction(Command command, Displayable displayable) {
      // write pre-action user code here
      if (displayable == FallSem_Home) {
          if (command == backCommand) {
              // write pre-action user code here
  
              // write post-action user code here
          } else if (command == exit_StudList) {
              // write pre-action user code here
              //notifyDestroyed();
  
              // write post-action user code here
          } else if (command == okCommand) {
              // write pre-action user code here
  
  
              // write post-action user code here
          }
      } else if (displayable == WinterSem_Home) {
          if (command == backCommand) {
              // write pre-action user code here
              switchToPreviousDisplayable();
              // write post-action user code here
          } else if (command == exitCommand2) {
              // write pre-action user code here
  
              // write post-action user code here
          }
      } else if (displayable == loginScreen) {
          if (command == LoginScreen.LOGIN_COMMAND) {
              // write pre-action user code here
              if(loginScreen.getUsername().equals("mohit") &amp;&amp; loginScreen.getPassword().equals("abhi")){
                  switchDisplayable(null, getStud_homelist());
              // write post-action user code here
              }
          }
      } else if (displayable == stud_homelist) {
          if (command == List.SELECT_COMMAND) {
              // write pre-action user code here
              stud_homelistAction();
              // write post-action user code here
          } else if (command == exit_StudList) {
              // write pre-action user code here
              exitMIDlet();
              // write post-action user code here
          } **else if (command == ok_StudList) {
              // write pre-action user code here
              List options = (List) display.getCurrent();
              switch(options.getSelectedIndex()){
                  case 0:
  
                      displayable = fall_sem.getForm();
                      switchDisplayable(null, displayable);
                      //display.setCurrent(fall_sem.getForm());
              }
  
              // write post-action user code here
          }**
      }
      // write post-action user code here
  }
  
  public LoginScreen getLoginScreen() {
      if (loginScreen == null) {
          // write pre-init user code here
          loginScreen = new LoginScreen(getDisplay());
          loginScreen.setLabelTexts("Username", "Password");
          loginScreen.setTitle("loginScreen");
          loginScreen.addCommand(LoginScreen.LOGIN_COMMAND);
          loginScreen.setCommandListener(this);
          loginScreen.setFullScreenMode(true);
          loginScreen.setBGColor(-3355444);
          loginScreen.setFGColor(0);
          loginScreen.setPassword("");
          loginScreen.setUsername("");
          loginScreen.setUseLoginButton(true);
          loginScreen.setLoginButtonText("Login");
          // write post-init user code here
      }
      return loginScreen;
  }
  
  public Form getFallSem_Home() {
      if (FallSem_Home == null) {
          // write pre-init user code here
          FallSem_Home = new Form("form", new Item[]{getChoiceGroup()});
          FallSem_Home.addCommand(getExit_StudList());
          FallSem_Home.addCommand(getBackCommand());
          FallSem_Home.addCommand(getOkCommand());
          FallSem_Home.setCommandListener(this);
          // write post-init user code here
      }
      return FallSem_Home;
  }
  
  public Command getExit_StudList() {
      if (exit_StudList == null) {
          // write pre-init user code here
          exit_StudList = new Command("Exit", Command.EXIT, 0);
          // write post-init user code here
      }
      return exit_StudList;
  }
  
  public ChoiceGroup getChoiceGroup() {
      if (choiceGroup == null) {
          // write pre-init user code here
          choiceGroup = new ChoiceGroup("choices", Choice.EXCLUSIVE);
          choiceGroup.append("Time Table", null);
          choiceGroup.append("Exam Schedule", null);
          choiceGroup.append("Marks", null);
          choiceGroup.setFitPolicy(Choice.TEXT_WRAP_DEFAULT);
          choiceGroup.setSelectedFlags(new boolean[]{false, false, false});
          // write post-init user code here
      }
      return choiceGroup;
  }
  
  public List getStud_homelist() {
      if (stud_homelist == null) {
          // write pre-init user code here
          stud_homelist = new List("list", Choice.IMPLICIT);
          stud_homelist.append("Fall Sem 2012-13", null);
          stud_homelist.append("Winter Sem 2012-13", null);
          stud_homelist.append("Add / Drop", null);
          stud_homelist.addCommand(getExit_StudList());
          stud_homelist.addCommand(getOk_StudList());
          stud_homelist.setCommandListener(this);
          stud_homelist.setSelectedFlags(new boolean[]{false, false, false});
          // write post-init user code here
      }
      return stud_homelist;
  }
  
  public void stud_homelistAction() {
      // enter pre-action user code here
      String __selectedString = getStud_homelist().getString(getStud_homelist().getSelectedIndex());
      if (__selectedString != null) {
          if (__selectedString.equals("Fall Sem 2012-13")) {
              // write pre-action user code here
  
              // write post-action user code here
          } else if (__selectedString.equals("Winter Sem 2012-13")) {
              // write pre-action user code here
  
              // write post-action user code here
          } else if (__selectedString.equals("Add / Drop")) {
              // write pre-action user code here
  
              // write post-action user code here
          }
      }
      // enter post-action user code here
  }
  
  public Form getWinterSem_Home() {
      if (WinterSem_Home == null) {
          // write pre-init user code here
          WinterSem_Home = new Form("form");
          WinterSem_Home.addCommand(getBackCommand());
          WinterSem_Home.addCommand(getExitCommand2());
          WinterSem_Home.setCommandListener(this);
          // write post-init user code here
      }
      return WinterSem_Home;
  }
  
  public Command getExitCommand1() {
      if (exitCommand1 == null) {
          // write pre-init user code here
          exitCommand1 = new Command("Exit", Command.EXIT, 0);
          // write post-init user code here
      }
      return exitCommand1;
  }
  
  public Command getBackCommand() {
      if (backCommand == null) {
          // write pre-init user code here
          backCommand = new Command("Back", Command.BACK, 0);
          // write post-init user code here
      }
      return backCommand;
  }
  
  public Command getExitCommand2() {
      if (exitCommand2 == null) {
          // write pre-init user code here
          exitCommand2 = new Command("Exit", Command.EXIT, 0);
          // write post-init user code here
      }
      return exitCommand2;
  }
  
  
  public Command getOkCommand() {
      if (okCommand == null) {
          // write pre-init user code here
          okCommand = new Command("Ok", Command.OK, 0);
          // write post-init user code here
      }
      return okCommand;
  }
  
  public Command getOk_StudList() {
      if (ok_StudList == null) {
          // write pre-init user code here
          ok_StudList = new Command("Ok", Command.OK, 0);
          // write post-init user code here
      }
      return ok_StudList;
  }
  
  public Display getDisplay() {
      return Display.getDisplay(this);
  }
  
  public void exitMIDlet() {
      switchDisplayable(null, null);
      destroyApp(true);
      notifyDestroyed();
  }
  
  public void startApp() {
      if (midletPaused) {
          resumeMIDlet();
      } else {
          initialize();
          startMIDlet();
      }
      midletPaused = false;
  }
  
  public void pauseApp() {
      midletPaused = true;
  }
  
  public void destroyApp(boolean unconditional) {
              notifyDestroyed();
  
  }
  }
  
  
  
   //Fall_Sem.java
  package mobileapp1;
  
  import javax.microedition.midlet.*;
  import javax.microedition.lcdui.*;
  import org.netbeans.microedition.lcdui.LoginScreen;
  import org.netbeans.microedition.lcdui.SimpleTableModel;
  import org.netbeans.microedition.lcdui.TableItem;
  
  public class Fall_Sem extends MIDlet implements CommandListener {
  
  private boolean midletPaused = false;
  private Display display;
  
  private Form form;
  private ChoiceGroup choiceGroup;
  private Form form1;
  private TableItem tableItem;
  private Command backCommand;
  private Command okCommand;
  private Command exitCommand;
  private Command exitCommand1;
  private Command backCommand1;
  private SimpleTableModel simpleTableModel;
  public Fall_Sem() {
      System.out.println("Fall Sem");
  }
  
  private void initialize() {                                         
      // write pre-initialize user code here
  
      // write post-initialize user code here
  }                            
  public void startMIDlet() {                                      
      // write pre-action user code here
      switchDisplayable(null, getForm());                                        
      // write post-action user code here
  }                             
  public void resumeMIDlet() {                                       
      // write pre-action user code here
  
      // write post-action user code here
  }                              
  public void switchDisplayable(Alert alert, Displayable nextDisplayable) {                                            
      // write pre-switch user code here
      Display display = getDisplay();                                               
      if (alert == null) {
          display.setCurrent(nextDisplayable);
      } else {
          display.setCurrent(alert, nextDisplayable);
      }                                             
      // write post-switch user code here
  }                                   
  public Form getForm() {
      if (form == null) {                                 
          // write pre-init user code here
          form = new Form("form", new Item[] getChoiceGroup()});                                    
          form.addCommand(getBackCommand());
          form.addCommand(getOkCommand());
          form.addCommand(getExitCommand());
          form.setCommandListener(this);                                  
          // write post-init user code here
      }                         
      return form;
  }
  public ChoiceGroup getChoiceGroup() {
      if (choiceGroup == null) {                                 
          // write pre-init user code here
          choiceGroup = new ChoiceGroup("Choices", Choice.EXCLUSIVE);                                    
          choiceGroup.append("Time Table", null);
          choiceGroup.append("Exam Schedule", null);
          choiceGroup.append("Marks", null);
          choiceGroup.setSelectedFlags(new boolean[]{false, false, false});                                  
          // write post-init user code here
      }                         
      return choiceGroup;
  }
  public void commandAction(Command command, Displayable displayable) {                                               
      // write pre-action user code here
      if (displayable == form) {                                           
          if (command == backCommand) {                                         
              // write pre-action user code here
  
              // write post-action user code here
          } else if (command == exitCommand) {                                          
              // write pre-action user code here
              exitMIDlet();                                           
              // write post-action user code here
          } else if (command == okCommand) {                                          
              // write pre-action user code here
              switchDisplayable(null, getForm1());                                           
              // write post-action user code here
          }                                           
      } else if (displayable == form1) {
          if (command == backCommand1) {                                         
              // write pre-action user code here
  
              // write post-action user code here
          } else if (command == exitCommand1) {                                          
              // write pre-action user code here
              exitMIDlet();                                            
              // write post-action user code here
          }                                                   
      }                                                 
      // write post-action user code here
  }                                             
  public Form getForm1() {
      if (form1 == null) {                                 
          // write pre-init user code here
          form1 = new Form("form1", new Item[]{getTableItem()});                                    
          form1.addCommand(getBackCommand1());
          form1.addCommand(getExitCommand1());
          form1.setCommandListener(this);                                  
          // write post-init user code here
      }                         
      return form1;
  }
  public TableItem getTableItem() {
      if (tableItem == null) {                                 
          // write pre-init user code here
          tableItem = new TableItem(getDisplay(), "tableItem");                                   
          // write post-init user code here
  
      }                         
      return tableItem;
  }
  public Command getBackCommand() {
      if (backCommand == null) {                                 
          // write pre-init user code here
          backCommand = new Command("Back", Command.BACK, 0);                                   
          // write post-init user code here
      }                         
      return backCommand;
  }
  public Command getOkCommand() {
      if (okCommand == null) {                                 
          // write pre-init user code here
          okCommand = new Command("Ok", Command.OK, 0);                                   
          // write post-init user code here
      }                         
      return okCommand;
  }
  public Command getExitCommand() {
      if (exitCommand == null) {                                 
          // write pre-init user code here
          exitCommand = new Command("Exit", Command.EXIT, 0);                                   
          // write post-init user code here
      }                         
      return exitCommand;
  }
  public Command getBackCommand1() {
      if (backCommand1 == null) {                                 
          // write pre-init user code here
          backCommand1 = new Command("Back", Command.BACK, 0);                                   
          // write post-init user code here
      }                         
      return backCommand1;
  }
  public Command getExitCommand1() {
      if (exitCommand1 == null) {                                 
          // write pre-init user code here
          exitCommand1 = new Command("Exit", Command.EXIT, 0);                                   
          // write post-init user code here
      }                         
      return exitCommand1;
  }
  public SimpleTableModel getSimpleTableModel() {
      if (simpleTableModel == null) {                                 
          // write pre-init user code here
          simpleTableModel = new SimpleTableModel(null, null);                                   
          // write post-init user code here
      }                         
      return simpleTableModel;
  }
  public Display getDisplay() {
      return Display.getDisplay(this);
  }
  
  public void exitMIDlet() {
      switchDisplayable(null, null);
      destroyApp(true);
      notifyDestroyed();
  }
  
  public void startApp() {
      if (midletPaused) {
          resumeMIDlet();
      } else {
          initialize();
          startMIDlet();
      }
      midletPaused = false;
  }
  
  public void pauseApp() {
      midletPaused = true;
  }
  
  public void destroyApp(boolean unconditional) {
  }
  }
  </code></pre>