NullPointerException tries to add 2 mappings in one mobile application

I'm just trying to understand the logic of why I have a mistake. I am trying to add 2 mappings to 1 for the first time and switch views using commandListener. I thought it was logical, I did everything right, but I get a null pointer exception. I never want to know the answers, I really like to work, so maybe someone can ask me a question about what I'm trying to achieve, which can make me think about the answer using your tips or hints. Will be appreciated.

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


public class ClassApp extends MIDlet implements CommandListener {
    private Display mydisplay;

    private TextBox d;
    private Alert alert;
    private Command c,e,f,mNextCommand,l;
    private List mList;

    public ClassApp(){

        alert = new Alert("Listen", "Do you really want to start this app?", null, null);
        alert.setTimeout(Alert.FOREVER);

        c = new Command("Exit", Command.EXIT, 2);
        e = new Command("Back", Command.BACK, 0);
        f = new Command("Alert", Command.SCREEN, 3);
        mNextCommand = new Command("Next", Command.SCREEN, 4);
        l = new Command("List", Command.SCREEN, 3);


        d = new TextBox("ClassApp", "Commander", 20, TextField.ANY | TextField.PASSWORD); 
        d.addCommand(c);
        d.addCommand(e);
        d.addCommand(f);
        d.addCommand(l);
        d.setCommandListener(this);
        mList.addCommand(mNextCommand);
        mList.setCommandListener(this);


        String[] stringElements = { "Airplane", "Car", "Hotel" };
        Image[] imageElements = { loadImage("/airplane.png"),
        loadImage("/car.png"), loadImage("/hotel.png") };

        mList = new List("Reservation type", List.IMPLICIT,
        stringElements, imageElements);




    }
    public void startApp() 
    {

        mydisplay = Display.getDisplay(this);
        mydisplay.setCurrent(d);

    }
    public void commandAction(Command j, Displayable s) 
            { 
                if(j == f)
                    mydisplay.setCurrent(alert);
                if(j == l)
                    mydisplay.setCurrent(mList);
                if (j == mNextCommand || j == List.SELECT_COMMAND) {
                int index = mList.getSelectedIndex();
                Alert alert2 = new Alert("Your selection",
                "You chose " + mList.getString(index) + ".",
                null, AlertType.INFO);
                mydisplay = Display.getDisplay(this);
                mydisplay.setCurrent(alert2, mList);
        }

                else if(j == c)
                    notifyDestroyed();
            }





    public void pauseApp() { } 
    public void destroyApp(boolean unconditional) { }
    private Image loadImage(String name) {
        Image image = null;
        try {
        image = Image.createImage(name);
        }
        catch (IOException ioe) {
        System.out.println(ioe);
        }
        return image;
    }
}

And I get the error:

Starting emulator in execution mode
Installing suite from: http://127.0.0.1:2913/ClassApp.jad
java.lang.NullPointerException:   0
    at ClassApp.<init>(ClassApp.java:33)
    at java.lang.Class.newInstance(), bci=0
    at com.sun.midp.main.CldcMIDletLoader.newInstance(), bci=46
    at com.sun.midp.midlet.MIDletStateHandler.createMIDlet(), bci=66
    at com.sun.midp.midlet.MIDletStateHandler.createAndRegisterMIDlet(), bci=17
    at com.sun.midp.midlet.MIDletStateHandler.startSuite(), bci=27
    at com.sun.midp.main.AbstractMIDletSuiteLoader.startSuite(), bci=52
    at com.sun.midp.main.CldcMIDletSuiteLoader.startSuite(), bci=8
    at com.sun.midp.main.AbstractMIDletSuiteLoader.runMIDletSuite(), bci=161
    at com.sun.midp.main.AppIsolateMIDletSuiteLoader.main(), bci=26
+3
source share
1 answer

, - , , , ...

.

ClassApp.java:33 , ClassApp.java . , ClassApp.<init> , ClassApp .

, 33 , , , :

    mList.addCommand(mNextCommand);

, , mList ( 20 ), , , .


, , , - NullPointerException, .

null - .

, , , .


PS.

(, startapp)

startApp , .

, startApp . , , : " , startApp() , , .."

, , . - startApp - , , .

+2

All Articles