j2me midlet问题的多个实例
我有一个在手机上运行的 j2me midlet。 该代码工作正常,但出现的问题是该程序似乎正在运行多个自身实例。 我在应用程序开头的 appStart() 方法中有代码,该代码在应用程序启动时运行两次。 在程序的生命周期中,当文本写入屏幕时,可以看到代码运行了两次。
代码如下所示:
public MyClass()
{
form = new Form("MyProgram");
cmdClose = new Command("EXIT", Command.EXIT, 1);
form.addCommand(cmdClose);
form.setCommandListener(this);
display = Display.getDisplay(this);
display.setCurrent(form);
}
public void startApp()
{
form.append("App starting\n");
// Rest of program
}
我不知道为什么代码被调用两次。
我正在 i290 上编码。
I have a j2me midlet running on a cell phone. The code works fine, but the issue that comes up is that the program seems to be running more than one instance of itself. I have code at the beginning of the application inside the appStart() method that runs twice when the application starts. During the lifetime of the program, the code can be seen running twice when text is written to the screen.
The code looks like this:
public MyClass()
{
form = new Form("MyProgram");
cmdClose = new Command("EXIT", Command.EXIT, 1);
form.addCommand(cmdClose);
form.setCommandListener(this);
display = Display.getDisplay(this);
display.setCurrent(form);
}
public void startApp()
{
form.append("App starting\n");
// Rest of program
}
I have no idea why the code is being called twice.
I'm coding on the i290.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这绝对是一个 JVM 错误。
startApp()
只能在启动时调用一次,并且在调用pauseApp()
或调用notifyPaused()
之前不能再次调用你自己。我建议的是以下代码:
这样您就可以跟踪 midlet 状态更改。 但事实上,最好根本不使用此方法,而使用构造函数。
哦,顺便说一句,我不认为存在多个实例或类似的情况,这只是一个 JVM 错误。
This is definitely a JVM bug.
startApp()
should be called only once at startup and can't be called again untilpauseApp()
is called or you callnotifyPaused()
yourself.What I suggest is the following code:
This way you can track midlet state changes. But in fact it is better that you don't use this method at all and use constructor instead.
Oh, by the way, I don't think that there are some multiple instances or something like that, this is merely a JVM error.
也许您做了一些操作,导致运行时调用
pauseApp()
,然后当您将焦点设置到应用程序时,运行时再次调用startApp()
。将日志记录放入
pauseApp()
中,看看会发生什么。Maybe you did something that made the runtime call
pauseApp()
and then when you set the focus to the app the runtime calledstartApp()
again.Put logging in
pauseApp()
and see what happens.