J2ME程序的奇怪现象

本文介绍了一个Java MIDP程序在周日正常运行但在之后出现IllegalMonitorStateException异常的情况。作者分享了完整的代码示例及遇到的具体错误信息,旨在探讨可能的问题原因及解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

      我周日写的程序,当时运行是没有问题的。今天运行奇了怪出问题。我看了代码没有问题就是出异常。代码如下
None.gifimport javax.microedition.lcdui.Command;
None.gif
import javax.microedition.lcdui.CommandListener;
None.gif
import javax.microedition.lcdui.Display;
None.gif
import javax.microedition.lcdui.Displayable;
None.gif
import javax.microedition.lcdui.Form;
None.gif
import javax.microedition.midlet.MIDlet;
None.gif
import javax.microedition.midlet.MIDletStateChangeException;
None.gif
None.gif
ExpandedBlockStart.gifContractedBlock.gif
public class TestExit extends MIDlet implements CommandListener dot.gif{
InBlock.gif    
private Display display;
InBlock.gif    
private Form form;
InBlock.gif    
private final static Command cmd_exit=new Command("EXit",Command.EXIT,1);
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
public TestExit() dot.gif{
InBlock.gif        display
=Display.getDisplay(this);
InBlock.gif        form
=new Form("Exit");
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
protected void destroyApp(boolean arg0) throws MIDletStateChangeException dot.gif{
InBlock.gif
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
protected void pauseApp() dot.gif{
InBlock.gif
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
protected void startApp() throws MIDletStateChangeException dot.gif{
InBlock.gif        form.addCommand(cmd_exit);
InBlock.gif        form.setCommandListener(
this);        
InBlock.gif        display.setCurrent(form);
InBlock.gif
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
public void commandAction(Command c, Displayable d) dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if(c==cmd_exit)dot.gif{
InBlock.gif            System.out.println(
"in");
ExpandedSubBlockStart.gifContractedSubBlock.gif            
try dot.gif{
InBlock.gif                destroyApp(
false);
InBlock.gif                notifyAll();
ExpandedSubBlockStart.gifContractedSubBlock.gif            }
 catch (MIDletStateChangeException e) dot.gif{
InBlock.gif                e.printStackTrace();
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedBlockEnd.gif}

None.gif
出的错误如下:
None.gifjava.lang.IllegalMonitorStateException
None.gif    at TestExit.commandAction(
+24)
None.gif    at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(
+280)
None.gif    at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(
+10)
None.gif    at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(
+68)
None.gif    at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(
+258)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值