J2ME Wireless ToolKit底下的 一个问题(我下面的代码怎么调试不成功?)(50分)

  • 主题发起人 主题发起人 SevenOrient
  • 开始时间 开始时间
S

SevenOrient

Unregistered / Unconfirmed
GUEST, unregistred user!
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class bbb extends MIDlet implements CommandListener
{
private Display firstDisplay ;
private Form firstForm ;
private Commanddo
neCommand;
public bbb()
{
firstDisplay = Display.getDisplay(this) ;
do
neCommand = new Command("DONE", Command.SCREEN, 1);
firstForm = new Form("Hello,测试") ;
StringItem firstStrItem = new StringItem("哈罗","米德列特") ;
firstForm.append(firstStrItem) ;
System.out.println("MIDlet启动") ;
}
protected void startApp() throws MIDletStateChangeException
{
TextBox textBox = new TextBox("Hello Midlet", "Hello !!", 256, 0);
textBox.addCommand(doneCommand);
textBox.setCommandListener( (CommandListener) this);
firstDisplay.setCurrent(firstForm) ;
firstDisplay.setCurrent(textBox);
}
protected void pauseApp()
{
}
protected void destroyApp(boolean unconditional) throws MIDletStateChangeException
{
}
public void commandAction(Command command, Displayable screen)
{
if (command ==do
neCommand){
destroyApp(false);
notifyDestroyed();
}
}
}
 
wo 我已经修改成它,还有错误:
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class bbb extends MIDlet implements CommandListener
{
private Display firstDisplay ;
private Form firstForm ;
private Commanddo
neCommand;
public bbb()
{
firstDisplay = Display.getDisplay(this) ;
do
neCommand = new Command("DONE", Command.SCREEN, 1);
firstForm = new Form("Hello,测试") ;
StringItem firstStrItem = new StringItem("哈罗","米德列特") ;
firstForm.append(firstStrItem) ;
System.out.println("MIDlet启动") ;
}
protected void startApp() throws MIDletStateChangeException
{
//TextBox textBox = new TextBox("Hello Midlet", "Hello !!", 256, 0);
//textBox.addCommand(doneCommand);
//textBox.setCommandListener( (CommandListener) this);
firstForm.addCommand(doneCommand);
firstForm.setCommandListener(this);
firstDisplay.setCurrent(firstForm) ;
//firstDisplay.setCurrent(textBox);
}
protected void pauseApp()
{
}
protected void destroyApp(boolean unconditional) throws MIDletStateChangeException
{
}
public void commandAction(Command command, Displayable screen)
{
if (command ==do
neCommand){
destroyApp(false);
notifyDestroyed();
}
}
}
*********************************提示:
:/J2mewtk/apps/bbb/src/bbb/test/bbb.java:40: unreported exception javax.microedition.midlet.MIDletStateChangeException;
must be caught or declared to be thrown
destroyApp(false);
^
1 error
com.sun.kvem.ktools.ExecutionException
Build failed
************************************
去掉
protected void destroyApp(boolean unconditional) throws MIDletStateChangeException
{
}
也不行。还必须有!!!
 
我想结束问题呀
 
错误因为是 commandAction 调用了 destroyApp。而 destroyApp 会抛出 MIDletStateChangeException。
所以,最好在 commandAction 里面截获掉这个异常
public void commandAction(Command command, Displayable screen) {
if (command ==do
neCommand){
try {
destroyApp(false);
notifyDestroyed();
}
catch(MIDletStateChangeException ex) {
//
}
}
}
顺便问一句,那些中文能显示吗?
 
能显示。而且第一屏幕的也可以用中文显示:)
 
其實只要碰上這種信息一般都要加上錯誤截取語句 catch
unreported exception javax.microedition.midlet.MIDletStateChangeException;
must be caught or declared to be thrown
destroyApp(false);
^
1 error
com.sun.kvem.ktools.ExecutionException
我在測試你這個程式
 
后退
顶部