站内搜索: 请输入搜索关键词

当前页面: 开发资料首页J2ME 专题模拟手机出现后,不显现文字,自动退出,求达人解!!!

模拟手机出现后,不显现文字,自动退出,求达人解!!!

摘要: 模拟手机出现后,不显现文字,自动退出,求达人解!!!


eclipse3.1.1+eclipseme1.2.3+wtk2.2
第一次写J2ME程序,一个HelloWorld程序,写完后,运行,可以正常显现.
将HelloWorld改为中文,再运行, 模拟手机出现后,不显现文字,自动退出.
再次改回为HellowWorld,运行,依旧为模拟手机出现后,不显现文字,自动退出.

附报告:
Warning: Running JAM, Ignoring all other options (but "-Xheapsize", and OTA flags if provided)
正在通过存储根 DefaultColorPhone 来运行
** Error installing suite (39): The JAD matches a version of a suite already installed.
Execution completed.
229355 bytecodes executed
6 thread switches
738 classes in the system (including system classes)
1451 dynamic objects allocated (60356 bytes)
1 garbage collections (0 bytes collected)

程序:
public class helloworld extends MIDlet {

public helloworld() {
super();
// TODO Auto-generated constructor stub
Form form = new Form("我的第一个J2ME程序!");
form.append("Welcome me back to J2ME World!");
Display.getDisplay(this).setCurrent(form);
}



请达人解,非常感谢!!!!



public class helloworld extends MIDlet {
Form form = new Form("我的第一个J2ME程序!");
form.append("Welcome me back to J2ME World!");
public helloworld() {
super();
// TODO Auto-generated constructor stub

Display.getDisplay(this).setCurrent(form);
}
}


楼上:这样改运行报错,连from的append方法都不认了.
不过非常感谢您的解答.



import javax.microedition.midlet.*;/*MIDlet implements CommandListener*/
import javax.microedition.lcdui.*;

public class HelloWorld extends MIDlet implements CommandListener
{
private DrawCanvasdrawCav= new DrawCanvas();
private Display myDisplay;
private Command DrawCommand
= new Command("Draw", Command.SCREEN, 1);
private Command ExitCommand
= new Command("Exit", Command.EXIT, 1);

public HelloWorld() {
drawCav.setDrawSt("HelloWorld!!What are you do?");
myDisplay.getDisplay(this).setCurrent(drawCav);
drawCav.setCommandListener(this);
drawCav.addCommand(ExitCommand);
drawCav.addCommand(DrawCommand);
}
protected void startApp() throws MIDletStateChangeException
{
;
}
protected void pauseApp() {}
protected void destroyApp(boolean unconditional)throws MIDletStateChangeException
{
myDisplay.setCurrent((Displayable)null);
destroyApp(true);
notifyDestroyed();
//drawCav.destroy();
}
public void commandAction(Command cmd, Displayable disp)
{
//drawCav.addCommand(getCurrentCommand());
if (cmd == DrawCommand)
drawCav.setDrawSt("Press down Draw.");
if (cmd == ExitCommand)
drawCav.setDrawSt("按下了Exit按钮.");
drawCav.repaint();
}
}


/*
* DrawCanvas.java
*
* Copyright 2001 SkyArts. All Rights Reserved.
*/
import javax.microedition.lcdui.*;

/**
* 字符串显示用的Canvas类别
*
* @author Hideki Yonekawa
* @version 1.0
*/
class DrawCanvas extends Canvas {
/** 描绘字符串内容的变量 */
private StringdrawSt;

/** 描绘的方法 */
protected void paint(Graphics g) {
// 背景涂白
g.setColor(0x00FFFFFF);
g.fillRect(0, 0, getWidth(), getHeight());

// 颜色指定为黑色
g.setColor(0x00000000);
g.drawLine(40,40,100,100);
// 描绘文字
g.drawString(drawSt, 10, 10, Graphics.TOP|Graphics.LEFT);
}
protected void keyPressed(int keyCode) {
drawSt = String.valueOf(keyCode);
repaint();
}

/** 将字符串描绘到画面上的方法 */
void setDrawSt(String drawSt) {
this.drawSt = drawSt;
}
}



试验成功了,但还不知道原因.具体步骤如下:
将WorkSpace清空,重建工程,第一次运行正常,按"挂机"键退出虚拟手机.
将显示文字改为中文,运行,正常,按"X"键退出虚拟手机.
再运行,以后皆不正常.
再次清空WorkSpace,重建工程,每次按"挂机"键退出,无论怎么改显示的文字,皆正常.

问题改为,是否正常与否跟怎样退出虚拟手机有关?非常感谢各位!


同时非常感谢sunyanbiao_12,结贴时再谢!


↑返回目录
前一篇: J2ME是否可以控制手机?
后一篇: 关于手机图象的一个问题.