Application startup fails in N72, static initialization is to blame ?
Hi,
I wrote the following small code . It compiles an works fine in wtk emulator. But it just does not run in N72.
Then I tried to remove the static final fields one by one .. I did not try all of them , But removing some commands or removing the alert fixes the problem.
Also if I go lazy, initialize the variables in the startApp(), then this is not a problem.
Is it some kind of memory exception or a new bug revealed ?
[CODE]
/**
*
* @author Kamanashis Roy
*/
package net.ayaslive.miniim.ui;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class App extends MIDlet implements CommandListener {
private static App self = null;
private static Alert singleAlert = new Alert("TEST");
private final static Command YES_POSITIVE = new Command("YES", Command.OK, 1);
private final static Command NO_POSITIVE = new Command("NO", Command.CANCEL, 1);
private final static Command YES_NEGATIVE = new Command("YES", Command.CANCEL, 1);
private final static Command NO_NEGATIVE = new Command("NO", Command.OK, 1);
private final static Command OK_CMD = new Command("OK", Command.BACK, 1);
public void destroyApp(boolean unconditional) {
notifyDestroyed();
}
protected void pauseApp() {
}
public void commandAction(Command cmd, Displayable dis) {
}
/**
* Startup step
*/
private int step = 0;
protected void startApp() throws MIDletStateChangeException {
try {
Canvas canvas = new Canvas() {
protected void paint(Graphics g) {
final int height = getHeight();
final int width = getWidth();
final int halfHeight = height/2;
final int RESOLUTION = 15;
final int PADDING = 2;
final int fillWidth = width - RESOLUTION - RESOLUTION;
// clear
g.setColor(0xD3D7CF);
g.fillRect(0, 0, width, height);
// fill step%
g.setColor(0x888A85);
g.fillRect( RESOLUTION, halfHeight - RESOLUTION, fillWidth*step/100, RESOLUTION);
g.drawRoundRect(RESOLUTION, halfHeight - RESOLUTION, fillWidth, RESOLUTION, PADDING, PADDING);
}
};
// show the canvas
Display.getDisplay(this).setCurrent(canvas);
// show progress
for(int i=0; i<100; i+=10) {
this.step = i;
canvas.repaint();
canvas.serviceRepaints();
Thread.sleep(1000);
}
// cleanup
canvas = null;
} catch(Throwable t) {
t.printStackTrace();
}
}
}
[/CODE]
Re: Application startup fails in N72, static initialization is to blame ?
Hello
Tested your code in a Nokia 6682 (S60 2nd Edition FP2) and worked fine.
Could you give us more details about the error you get... any message?
My feeling is that could be a problem at packing the MIDLet... check that Jad file is correct.
Remember not to initialize variables in the startApp method ... you should do it in the MIDLet constructor... the reason is that startApp could be called more than once during the lifetime of the application.
: Ruben
Re: Application startup fails in N72, static initialization is to blame ?
Hi,
Thank you for your reply. And "not initialize in startApp" is really new thing for me :D . The problem is when I start the application, there is a flicker and the application goes dead.
Note, I tested it on N72(V 5.0734.4.0.1 22-08-07 RM-180) ..
Today I double checked the code with the same result. Earlier I used antenna, now tested with WTK 2.5.2 .. (could not find a way to attach, but the jar and jad is hosted here<http://miniim.sourceforge.net/n72tests> for some days, may be it can help)
Let me know if you want to know any information ..
-- Thanks