English 中文(简体)
使用按钮在 j2me 上浏览表单时的无点例外
原标题:NullPointException when I try to navigate forms on j2me using buttons

我无法按下按钮将主页与第二页连接。 它会抛出一个 NullPoint 例外 。 有人能告诉我哪里出错了吗?

import java.io.InputStream;
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.*;
import com.sun.lwuit.*;
import com.sun.lwuit.animations.CommonTransitions;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.layouts.BoxLayout;
import com.sun.lwuit.plaf.UIManager;
import com.sun.lwuit.util.Resources;
import java.io.IOException;

public class standings extends MIDlet implements ActionListener{

   public Command cmdSelect; 
   public Form fform, selectLgform;
   public Button btnSelectLeague,btnHelp,btnAbout,btnExit;
   public TextArea taHome,taAbout, taHelp, taSelectLg;
    private InputStream iStream;
    private StringBuffer strBuffer;
    private Form selectLgForm;
    public void startApp() {
        Display.init(this);
        try {
            Resources rs= Resources.open("/restheme.res");
            UIManager.getInstance().setThemeProps(rs.getTheme("Theme2"));
        } catch (Exception e) {
            e.getMessage();
        }
       displayMainForm();
    }

  public void displayMainForm()
  {
   fform = new Form("Football League Standings");
   taHome= new TextArea(5,20,TextArea.ANY);
   fform.setLayout(new BorderLayout());
   fform.setTransitionInAnimator(CommonTransitions.createFade(1000));
   iStream     = getClass().getResourceAsStream("/intro.txt");
   strBuffer   = new StringBuffer();
        int next    = 1;
        try {
            while((next = iStream.read()) != -1) {
                char nextChar = (char) next;
                strBuffer.append(nextChar);
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        }

        taHome.setText(strBuffer.toString());
        strBuffer   = null;
        taHome.setFocusable(false);
        taHome.setEditable(false);
        taHome.setUIID("Label");

        //fform.addComponent(BorderLayout.CENTER,taHome);

        btnSelectLeague= (new Button("Select league"));
        btnHelp= (new Button("Help"));
        btnAbout= (new Button("About"));
        btnExit= (new Button("Exit"));

    Container mcont = new Container(new BoxLayout(BoxLayout.Y_AXIS));
      mcont.addComponent(taHome);
      mcont.addComponent(btnSelectLeague);
      mcont.addComponent(btnHelp);
      mcont.addComponent(btnAbout);
      mcont.addComponent(btnExit);
      fform.addComponent(BorderLayout.CENTER, mcont);
      btnSelectLeague.addActionListener(this);
      btnHelp.addActionListener(this);
      btnAbout.addActionListener(this);
      btnExit.addActionListener(this);

   fform.show();
  }

  /* Command exitCommand = new Command("Exit");
   fform.addCommand(exitCommand);

   fform.addCommandListener(this);
    }
  }*/
   public void selectLgForm()
    {
        selectLgForm= new Form("Select League");
        taSelectLg= new TextArea(5,20,TextArea.ANY);
        selectLgForm.setLayout(new BorderLayout());
        selectLgForm.setTransitionInAnimator(CommonTransitions.createFade(1000));
        iStream     = getClass().getResourceAsStream("/selectlg.txt");
        strBuffer   = new StringBuffer();
        int next    = 1;
        try {
            while((next = iStream.read()) != -1) {
                char nextChar = (char) next;
                strBuffer.append(nextChar);
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        }

        taSelectLg.setText(strBuffer.toString());
        strBuffer   = null;
        taSelectLg.setFocusable(false);
        taSelectLg.setEditable(false);
        taSelectLg.setUIID("Label");

        selectLgForm.addComponent(BorderLayout.CENTER,taAbout);

    //START OF MENU BUTTONS
        selectLgForm.addCommand(new Command("Back")
        {
            public void actionPerformed(ActionEvent e)
            {
                displayMainForm();
            }


        });


        selectLgForm.show();
    }//END OF MENU BUTTONS


    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

  public void actionPerformed(ActionEvent ae) {
       if(ae.getSource()==btnSelectLeague){
            selectLgForm();
        }
问题回答

my best guesses are:
- selectLgForm.addComponent(BorderLayout.CENTER,taAbout) throws a NullPointerException because taAbout is null.
- or iStream = getClass().getResourceAsStream("/selectlg.txt"); throws a NullPointerException because the text file is not where you think it is.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签