企业移动应用平台的手机终端的UI显示是在lwuit框架上开发的,使用SUN WTK提供的模拟器,运行正常.开发环境配置如下:
Jdk1.4
Eclipse 3.2
Eclipseme1.7.9
Sun Wtk2.5.2
Midp2.0
CLDC1.1
[b]1.S60上的测试[/b]
然后准备在诺基亚S60模拟器下测试.于是噩梦开始了
1)nS60_jme_sdk_3rd_e_FP1.zip
运行配置:
在Emulation选项卡中指定设备
Group:S60
Devicie:S60Emulator
其他选项默认
运行时总出现如下错误.
当运行到: Connect to Agent时
eclipse提示错误对话框:
Failed to initialize session
Caught exception:
java.net.ConnectException:Connection refused:connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
看了网上的一些评论,发现普遍有这样的问题.解决办法好像是让换一个新的sdk版本试试.
2)nS60_jme_sdk_v2_6f.zip
运行配置同上
没有出现failed to initialize session 错误.耐心等待(时间很长),终于画面出来了:
再看后台提示:
-VM verbose connection exited
再看网上的资料,说可能是:S60网络连接与其他模拟器不同而引起的.
然后仔细分析代码,发现在打开主页面的这个过程并没有与服务器连接.
只好加入System.out.println进行调试.终于发现程序跑到lwuit出现了问题
[b]2.测试代码[/b]
于是写了一段测试代码
package test;import javax.microedition.midlet.*;import com.sun.lwuit.*;import com.sun.lwuit.events.*;import com.sun.lwuit.layouts.BorderLayout;import com.sun.lwuit.layouts.BoxLayout;import com.sun.lwuit.layouts.GridLayout;import com.sun.lwuit.plaf.Style;import com.sun.lwuit.plaf.UIManager;import com.sun.lwuit.util.Resources;/** * @author mfcai */public class HelloLWUITMIDlet extends MIDlet implements ActionListener { public void startApp() { Display.init(this); try{ Resources r = Resources.open("/javaTheme.res");// 主题文件路径 UIManager.getInstance().setThemeProps(r.getTheme( "javaTheme")); // 主题名称 System.out.println("theme_name is:javaTheme"); }catch(Exception ex){ System.out.println(ex.toString()); } Form f = new Form("Hello, LWUIT!"); f.show(); Command exitCommand = new Command("Exit"); f.addCommand(exitCommand); f.setCommandListener(this); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public void actionPerformed(ActionEvent ae) { notifyDestroyed(); }}
1)s60模拟器的效果
出的错误和前面运行程序出的一模一样.如图:
把这加载主题段代码注释掉
Resources r = Resources.open("/javaTheme.res");// 主题文件路径 UIManager.getInstance().setThemeProps(r.getTheme( "javaTheme")); // 主题名称 System.out.println("theme_name is:javaTheme");
2)代码修改后的效果
画面终于出来了.如下:
3)wtk模拟器的效果
在SUN WTK提供的模拟器下,画面显示如下:
[b]3.结论[/b]
s60并不能很好地支持lwuit.网上有资料说lwuit有很好的适应性,看来这句话未必很正确。
相关资源:N-Gage测试游戏