关于J2ME低级界面和高级界面跳转死机问题!!十万火急!!!高手帮忙!!!

liuxiaohui1987 2009-05-18 04:22:20
最近写了一个小软件,在模拟器上运行的时候一点事都没有,一切正常,放到手机上就有问题了,问题如下:
由于牵扯到发短信,需要由低级界面跳转到高级界面,由低跳高是正常,短信能发出去,发完要由高级跳回低级界面是出问题了,当跳回低级界面是就死机了,死在低级界面上了,按什么都没反应,只能关机重启手机,很郁闷。开始以为是内存爆了,内存溢出,可是也System.gc()了,该null的地方也null了,还是这问题。后来发现就是在界面跳转的时候死机的,各位高人,知不知道低级界面和高级界面之间跳转都有什么注意的,不小心会出什么问题,我这样的情况怎么解决!
重谢!!!!!!!代码如下:
public PoemCanvas(PoemMidlet midlet) {
logoi = 0;
g = null;
setFullScreenMode(true);
this.midlet = midlet;
canvasWidth = 176;
canvasHeight = 208;
getNum = "137xxxx9706";
try {
imgBack = Image.createImage("/back.png");
imgButton1 = Image.createImage("/button1.png");
} catch (IOException e) {
e.printStackTrace();
}
currentState = 1;
thread = new Thread(this);
thread.start();
}


protected void paint(Graphics g) {
this.g = g;
if (currentState != 5)
g.drawImage(imgBack, canvasWidth / 2, canvasHeight / 2, 0x1 | 0x2);
switch (currentState) {
default:
break;

case 1: // '\001'
if (logoi != 0) {
g.drawImage(imgButton1, (canvasWidth - imgButton1.getWidth())
/ 2 + logoi, (canvasHeight * 5) / 6, 0);
logoi = 0;
} else {
g.drawImage(imgButton1,
(canvasWidth - imgButton1.getWidth()) / 2,
(canvasHeight * 5) / 6, 0);
logoi = 1;
}
break;

case 2: // '\002'
g.drawImage(imgMenuBack,
(canvasWidth - imgMenuBack.getWidth()) / 2,
canvasHeight / 9, 0);
if (logoi != 0) {
g.drawImage(imgButton1, (canvasWidth - imgButton1.getWidth())
/ 2 + logoi, (canvasHeight * 5) / 6, 0);
logoi = 0;
} else {
g.drawImage(imgButton1,
(canvasWidth - imgButton1.getWidth()) / 2,
(canvasHeight * 5) / 6, 0);
logoi = 1;
}
g.setClip(0, 0, canvasWidth, imgMenuBack.getHeight());
g.drawImage(imgIntro, 0, playCount, 0);
if (playCount > 25)
playCount -= 3;

break;

case 3: // '\003'
g.drawImage(imgMenuBack,
(canvasWidth - imgMenuBack.getWidth()) / 2,
canvasHeight / 9, 0);
g.drawImage(imgButton2, (canvasWidth - imgButton2.getWidth()) / 2,
(canvasHeight - imgButton2.getHeight()) / 2 + 5, 0);
g.drawImage(imgButton3, x, y, 0);
g.drawImage(imgSignName,
(canvasWidth - imgSignName.getWidth()) / 2,
(canvasHeight - imgSignName.getHeight()) / 2 + 8, 0);
g.drawImage(imgExit, 0, canvasHeight - imgExit.getHeight(), 0);
g.drawImage(imgChoose, canvasWidth - imgChoose.getWidth(),
canvasHeight - imgChoose.getHeight(), 0);
break;

case 4: // '\004'
g.drawImage(imgCharge, (canvasWidth - imgCharge.getWidth()) / 2,
canvasHeight / 9, 0);
g.drawImage(imgGoBack, 0, canvasHeight - imgGoBack.getHeight(), 0);
g.drawImage(imgSend, canvasWidth - imgSend.getWidth(),
canvasHeight - imgSend.getHeight(), 0);
break;
}
}

protected void keyPressed(int keyCode) {
switch (currentState) {
case 5: // '\005'
default:
break;

case 3: // '\003'
switch (keyCode) {
case -7:
case -5:
switch (recentChoose) {
case 0: // '\0'
updateState(this.stateSend, this.stateMenu);
break;
case 1:
updateState(this.stateSend, this.stateMenu);
break;
case 2:
updateState(this.stateSend, this.stateMenu);
break;
case 3:
updateState(this.stateSend, this.stateMenu);
break;
case 4:
updateState(this.stateSend, this.stateMenu);
break;
case 5:
updateState(this.stateSend, this.stateMenu);
break;
}
break;
case 4: // '\004'
switch (keyCode) {
case -6:

updateState(this.stateMenu, this.stateSend);
break;

case -7:
case -5:
currentState = 5;
sendCommand = new Command("发送", 4, 1);
backCommand = new Command("返回", 7, 1);

massage = new TextField(null, null, 256, 0);
alert2 = new StringItem(null, "输入您要发送的内容(中文):", 0);
alert3 = new StringItem(null, "发送成功!", 0);
form = new Form("诗");
form.append(alert2);
form.append(massage);
form.addCommand(backCommand);
form.addCommand(sendCommand);
form.setCommandListener(this);
if(midlet.display==null)
midlet.display=Display.getDisplay(midlet);
Display.getDisplay(midlet).setCurrent(form);
break;
}
break;
}
}
public void run() {
do
try {
alertWin=new Alert(null,"短信发送成功,谢谢使用!",null,AlertType.WARNING);
if(midlet.display==null)
midlet.display=Display.getDisplay(midlet);

Display.getDisplay(midlet).setCurrent(alertWin);
isWin = false;
}
if (isNull) {

alertNull=new Alert(null,"对不起,短信不能为空!",null,AlertType.WARNING);
if(midlet.display==null)
midlet.display=Display.getDisplay(midlet);
Display.getDisplay(midlet).setCurrent(alertNull);
isNull = false;
}
Thread.sleep(100L);
repaint();
System.gc();
} catch (InterruptedException e) {
e.printStackTrace();
}
while (true);
}
public void commandAction(Command c, Displayable d) {
if (c == backCommand) {
if(midlet.display==null)
{
midlet.display=Display.getDisplay(midlet);
System.out.println("sdfsa");
}
Display.getDisplay(midlet).setCurrent(this);
updateState(this.stateMenu, this.stateSMS);

}
if (c == sendCommand)
{
getMassage = massage.getString();

if (getMassage.equals(""))// 如果用户输入的是空字符串
{
System.out.println("短信是空!");
this.updateState(this.stateNull, this.stateSend);
isNull = true;
}

else {

updateState(this.stateDo, this.stateSend);
(new Thread() {
public void run() {
isWin = SMSUtil.send(getMassage, getNum);
} }).start();
System.out.println(isWin);
}
}
if (c == backCommandNull) {
if(midlet.display==null)
midlet.display=Display.getDisplay(midlet);
// midlet.display.setCurrent(this);
Display.getDisplay(midlet).setCurrent(this);
updateState(this.stateSend, this.stateNull);
}
}

}
...全文
532 点赞 收藏 12
写回复
12 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
Lee2K 2009-05-19
呵呵.通道...
回复
zlzwind 2009-05-19
太强悍了,谢谢,需要的知识
回复
xuyan87101 2009-05-19
可以在TEXTFIEld中的一个方法观察你的短信内容是否为空,以前见过现在记不清了,你可以再API中看看
回复
liuxiaohui1987 2009-05-19
谢谢。
因为帖子要求的字数有限我就删掉了一些不牵扯逻辑的代码,就导致了这东西太乱,还是很感谢你能抽时间帮忙。
回复
kpbiao87 2009-05-19
回复
XXX86 2009-05-19
JAVA是开源的,读读源代码就可以搞定了。
回复
kf156 2009-05-18
下午稍看了下,但由于代码较多较乱,又没注释,所以一时不好定位你问题的所在。

要判断短信是否为空,可以在发送前先判断是否为空
为空,则提示alert;不为空,则发送短信
回复
liuxiaohui1987 2009-05-18
请大哥指教,我是想能及时判断出短信是空的,有需要改进的地方。
大哥指点一下我该怎么样在J2ME这方面改进,迷茫中!
现在我该学习些啥?
回复
liuxiaohui1987 2009-05-18
我去掉一些多余的代码,格式上会有些错误,重点逻辑都在,谢谢
回复
kf156 2009-05-18
public void run() {
do
try {
alertWin=new Alert(null,"短信发送成功,谢谢使用!",null,AlertType.WARNING);
if(midlet.display==null)
midlet.display=Display.getDisplay(midlet);

Display.getDisplay(midlet).setCurrent(alertWin);
isWin = false;
}
if (isNull) {

alertNull=new Alert(null,"对不起,短信不能为空!",null,AlertType.WARNING);
if(midlet.display==null)
midlet.display=Display.getDisplay(midlet);
Display.getDisplay(midlet).setCurrent(alertNull);
isNull = false;
}
Thread.sleep(100L);
repaint();
System.gc();
} catch (InterruptedException e) {
e.printStackTrace();
}
while (true);
}


括号都找不齐成对的...
回复
JarodYv 2009-05-18
你这程序写的有很大的问题。且不说逻辑控制上的混乱,单看run()方法,你在不断地new alert,并且把alert的跳转逻辑放到了线程中,这样很不安全啊!
不明白为什么要在线程中不断new alert呢?
回复
yangc_83 2009-05-18
看看MIDlet类
中断返回MOTO的机子会调用,STARTAPP()
回复
相关推荐
发帖
J2ME
创建于2007-09-28

1.3w+

社区成员

Java J2ME
申请成为版主
帖子事件
创建了帖子
2009-05-18 04:22
社区公告
暂无公告