关于按钮的奇怪问题

windy731 2009-06-15 11:31:28
出错提示见下面的帖子

http://topic.csdn.net/u/20090610/10/8ba603db-eb12-416b-996c-667c7dcc1c58.html

之后我写了一个测试程序,发现在commandAction方法中使用if (c == exit)就会报出帖子中的异常,而只要去掉就可以正常运行,也就是说程序无法处理多个事件,只能处理一个动作,郁闷啊,有人遇到过这样的问题吗???这是什么引起的?这么解决啊???

package main;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class Test extends MIDlet implements CommandListener {

private Display display;
private Form form;
private Command exit;

public Test() {
display = Display.getDisplay(this);
exit = new Command("退出", Command.SCREEN, 1);
form = new Form("测试Form");
form.addCommand(exit);
form.setCommandListener(this);
}

protected void destroyApp(boolean arg0) {}

protected void pauseApp() {}

protected void startApp() throws MIDletStateChangeException {
display.setCurrent(form);
}

public void commandAction(Command c, Displayable d) {
if (c == exit) {
destroyApp(true);
notifyDestroyed();
}
}

}
...全文
37 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
windy731 2009-06-16
  • 打赏
  • 举报
回复
问题解决,果然是打包的问题,我用WTK打包就没出现问题了,谢谢大家的帮忙~~~
隧便 2009-06-16
  • 打赏
  • 举报
回复
eclipse的打包打出来也不应该是这样的。。
windy731 2009-06-16
  • 打赏
  • 举报
回复
啊哦,我用的是eclipse带的打包工具,应该用什么工具打包???
kf156 2009-06-16
  • 打赏
  • 举报
回复
打的包有问题,包里还有JAD和.classpath等文件...
yangc_83 2009-06-16
  • 打赏
  • 举报
回复
模拟器一跑就死..
VM status:
Instruction pointer.: 10223e61 (offset within invoking method: 29)
Next instruction....: 0x4c
Frame pointer.......: e71000
Local pointer.......: e70fe4
Stack size..........: 128; sp: e71018; ranges: e70fb0-e711b0;
Contents of the current stack frame:
e70fe4: e71760 (lp)
e70fe8: 0
e70fec: ecc760
e70ff0: e73850
e70ff4: ecc774
e70ff8: 101747dc
e70ffc: ecc740
e71000: e70fc8 (fp)
e71004: 1024d539
e71008: e70fe0
e7100c: 1018b3f8
e71010: e70fa8
e71014: 0 (end of frame)
e71018: ee9a58 (sp)
Execution stack contains 108 items:
e71934
e7392c
是不是你包没打好啊,用WTK打,把源文件放在/src文件下,资源放在/res下,再打包
隧便 2009-06-16
  • 打赏
  • 举报
回复
你是用什么打包的。包怎么是这样的?
windy731 2009-06-15
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 kf156 的回复:]
用了你这段代码测试,没报异常...
[/Quote]

在真机上测试的吗?我在模拟器中运行也没有问题,一到真机上就死活加不上那个判断
windy731 2009-06-15
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 xnjnmn 的回复:]
public void commandAction(Command c, Displayable d) {
if (c == exit) {
System.out.println(exit.getLabel()+"----exit");
destroyApp(true);
notifyDestroyed();
}
}
经测试没有什么问题,我估计LZ您的是编码格式问题,我的工程编码为GBK
Running with storage root C:\Documents and Settings\Administrator\j2mewtk\2.5.2\appdb\temp.DefaultColo…
[/Quote]

应该与编码格式无关,我试了GBK,还是不行~~~
xnjnmn 2009-06-15
  • 打赏
  • 举报
回复
public void commandAction(Command c, Displayable d) {
if (c == exit) {
System.out.println(exit.getLabel()+"----exit");
destroyApp(true);
notifyDestroyed();
}
}
经测试没有什么问题,我估计LZ您的是编码格式问题,我的工程编码为GBK
Running with storage root C:\Documents and Settings\Administrator\j2mewtk\2.5.2\appdb\temp.DefaultColorPhone5
Running with locale: Chinese_People's Republic of China.936
Running in the identified_third_party security domain
退出----exit
Execution completed.
3404371 bytecodes executed
113 thread switches
1667 classes in the system (including system classes)
17653 dynamic objects allocated (528808 bytes)
2 garbage collections (457420 bytes collected)
kf156 2009-06-15
  • 打赏
  • 举报
回复
用了你这段代码测试,没报异常...
windy731 2009-06-15
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 xuxing0614 的回复:]
你打的包是cldc-1.1.。。改成1.0
[/Quote]

你指的是jad中的配置吧???jar中的配置是1.0的,jad文件没有用呢还。。。
隧便 2009-06-15
  • 打赏
  • 举报
回复
你打的包是cldc-1.1.。。改成1.0
windy731 2009-06-15
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 kf156 的回复:]
打包有没问题?把你打好的测试包传网上,我下载到6120c里测看看
[/Quote]

下载地址:http://www.anyuok.com/tool/TestA.jar

有劳了~~~
kf156 2009-06-15
  • 打赏
  • 举报
回复
打包有没问题?把你打好的测试包传网上,我下载到6120c里测看看
windy731 2009-06-15
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 xuxing0614 的回复:]
既然说了编码问题。你就把中文全部给英文然后试下。

加下这个测下,看打印出来什么问题。
try
{
if (c == exit) {
destroyApp(true);
notifyDestroyed();
}
}catch(Exception e)
{
form.append(e.toString());
}
[/Quote]

不是程序运行到这个位置才出错,而是在启动的时候就报错了,明白???
windy731 2009-06-15
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 yangc_83 的回复:]
模拟器没问题,换个变量名字看看?
怪问题!关注
[/Quote]

貌似没什么关系
隧便 2009-06-15
  • 打赏
  • 举报
回复
既然说了编码问题。你就把中文全部给英文然后试下。

加下这个测下,看打印出来什么问题。
try
{
if (c == exit) {
destroyApp(true);
notifyDestroyed();
}
}catch(Exception e)
{
form.append(e.toString());
}
yangc_83 2009-06-15
  • 打赏
  • 举报
回复
模拟器没问题,换个变量名字看看?
怪问题!关注
windy731 2009-06-15
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 kf156 的回复:]
6120c上测试没问题
你是哪款手机测有问题?换款呢?
[/Quote]

还是那个6708,只能是怀疑和uiq这个操作系统有关系了,正在挑一款s60带Wi-Fi功能的机器,有好的推荐吗?
kf156 2009-06-15
  • 打赏
  • 举报
回复
6120c上测试没问题
你是哪款手机测有问题?换款呢?

13,100

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧