如何在j2me中从一个页面导航到另一个页面

时间:2013-02-03 18:43:52

标签: list java-me uinavigationcontroller

我是J2ME的新手。我试图在ListItem的选择上从一个MIDlet页面导航到另一个页面。但我收到以下错误消息。

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: <at java.lang.NullPointerException:   0>, 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)

我不知道如何处理这一个。有人可以帮帮我吗?

//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 && 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") && 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) {
}
}

1 个答案:

答案 0 :(得分:1)

我在其他答案中写了一个关于如何进行基于列表选择导航的示例: Get event click list item in J2ME

相关问题