首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Exception >

OnlineHelp例子运行时异常:IllegalArgumentException

2014-01-26 
OnlineHelp例子运行时异常:IllegalArgumentException//-----------------------------// 这是从书中拷贝下

  OnlineHelp例子运行时异常:IllegalArgumentException  
  //-----------------------------
  // 这是从书中拷贝下来的。编译时没错,运行时发现此异常。
  // 请问错在哪?
  //-----------------------------
  import javax.microedition.midlet.*;
  import javax.microedition.lcdui.*;
  public class OnlineHelp extends MIDlet implements CommandListener
  {
  private Display display;
  private Command back;
  private Command exit;
  private Command help;
  private Form form;
  private TextBox helpMesg;
  public OnlineHelp()
  {
  display = Display.getDisplay(this);
  back = new Command("Back", Command.BACK, 2);
  exit = new Command("Exit", Command.EXIT, 1);
  help = new Command("Help", Command.HELP, 3);
  form = new Form("Online Help Example");
  helpMesg = new TextBox("Online Help", "Press Back to return to the previous screen or press Exit Exist to close this program.", 81, 0);
  helpMesg.addCommand(back);
  form.addCommand(exit);
  form.addCommand(help);
  form.setCommandListener(this);
  helpMesg.setCommandListener(this);
  }
  public void startApp()
  {
  display.setCurrent(form);
  }
  public void pauseApp()
  {
  }
  public void destroyApp(boolean unconditional)
  {
  }
  public void commandAction(Command command,
    Displayable displayable)
  {
  if (command == back)
  {
  display.setCurrent(form);
  }
  else if (command == exit)
  {
  destroyApp(false);
  notifyDestroyed();
  }
  else if (command == help)
  {
  display.setCurrent(helpMesg);
  }
  }
  }
 

------解决方法--------------------------------------------------------
  刚才看了很久也没有发现问题
  亲自在JB里运行了一下发现确是有IllegalArgumentException异常抛出
  根据异常信息步入原来是这一句的问题
  helpMesg = new TextBox("Online Help", "Press Back to return to the previous screen or press Exit Exist to close this program.", 81, 0);         

热点排行