当前位置: 代码迷 >> J2ME >> Uncaught exception java/lang/NullPointerException.解决方法
  详细解决方案

Uncaught exception java/lang/NullPointerException.解决方法

热度:3112   发布时间:2013-02-25 21:35:55.0
Uncaught exception java/lang/NullPointerException.
退出的时候出现Uncaught   exception   java/lang/NullPointerException.

帮帮忙看一下。
package   com.mobile;

import   javax.microedition.midlet.*;

import   javax.microedition.io.*;

import   javax.microedition.lcdui.*;

import   java.io.*;

public   class   SocketMIDlet   extends   MIDlet   implements   CommandListener   {

  private   static   final   String   SERVER   =   "Server ";

  private   static   final   String   CLIENT   =   "Client ";

  private   static   final   String[]   names   =   {   SERVER,   CLIENT   };

  private   static   Display   display;

  private   Form   f;

  private   ChoiceGroup   cg;

  private   boolean   isPaused;

  private   Server   server;

  private   Client   client;

  private   Command   exitCommand   =   new   Command( "Exit ",   Command.EXIT,   1);

  private   Command   startCommand   =   new   Command( "Start ",   Command.ITEM,   1);

  public   SocketMIDlet()   {

    display   =   Display.getDisplay(this);

    f   =   new   Form( "Socket   Demo ");

    cg   =   new   ChoiceGroup( "Please   select   peer ",   Choice.EXCLUSIVE,   names,

        null);

    f.append(cg);

    f.addCommand(exitCommand);

    f.addCommand(startCommand);

    f.setCommandListener(this);

    display.setCurrent(f);

  }

  public   boolean   isPaused()   {

    return   isPaused;

  }

  public   void   startApp()   {

    isPaused   =   false;

  }

  public   void   pauseApp()   {

    isPaused   =   true;

  }

  public   void   destroyApp(boolean   unconditional)   {
    if   (server   !=   null)   {

      server.stop();

    }
    if   (client   !=   null)   {

      client.stop();

    }
  }

  public   void   commandAction(Command   c,   Displayable   s)   {

    if   (c   ==   exitCommand)   {

      destroyApp(true);

      notifyDestroyed();

    }   else   if   (c   ==   startCommand)   {

      String   name   =   cg.getString(cg.getSelectedIndex());

      if   (SERVER.equals(name))   {

        server   =   new   Server(this);

        server.start();

      }   else   {

        client   =   new   Client(this);
  相关解决方案
本站暂不开放注册!
内测阶段只得通过邀请码进行注册!
 
  • 最近登录:Wed Dec 13 03:51:31 CST 2017
  • 最近登录:Wed Dec 13 03:51:31 CST 2017
  • 最近登录:Wed Dec 13 03:51:31 CST 2017
  • 最近登录:Wed Dec 13 03:51:31 CST 2017
  • 最近登录:Wed Dec 13 03:51:31 CST 2017