IllegalAccessException starting my J2ME app

I have this code in Test.java:

import javax.microedition.midlet.*;

import javax.microedition.lcdui.*;

import javax.microedition.lcdui.game.*;

publicclass Testextends MIDletimplements CommandListener

{

TestCanvas canvas;

public Test(){}

publicvoid startApp()

{

canvas =new TestCanvas(Display.getDisplay(this));

canvas.addCommand(exitCommand);

canvas.setCommandListener(this);

canvas.start();

}

publicvoid destroyApp(boolean unconditional)throws MIDletStateChangeException

{}

publicvoid pauseApp()

{}

private Command exitCommand =new Command("Exit", Command.EXIT, 99);

publicvoid commandAction(Command c, Displayable s)

{

if(c == exitCommand)

{

try

{

destroyApp(false);

notifyDestroyed();

}

catch (MIDletStateChangeException ex)

{}

}

}

}

class TestCanvasextends GameCanvasimplements Runnable

{

Display display;

public TestCanvas(Display d)

{

super(false);

display = d;

}

void start()

{

display.setCurrent(this);

repaint();

}

publicvoid run()

{

Graphics g = getGraphics();

while (true)

{

g.setColor(0x0000FF);

g.fillRect(0, 0, getWidth(), getHeight());

g.setColor(0xFFFFFF);

int keyState = getKeyStates();

if ((keyState & LEFT_PRESSED) != 0)

{

g.drawString("left", 0, 0, 0);

}

elseif ((keyState & RIGHT_PRESSED) != 0)

{

g.drawString("right", 0, 0, 0);

}

flushGraphics();

}

}

}

When I build it with the Wireless Toolkit and run it in the emulator, I get this in the WTK window:

Unable to create MIDlet Test

java.lang.IllegalAccessException

at com.sun.midp.midlet.MIDletState.createMIDlet(+34)

at com.sun.midp.midlet.Selector.run(+22)

If I try it on my cell phone (Sony Ericsson W300i), it just gives me a blank white screen.

Any ideas on what's going on?

[4451 byte] By [mmiikkee13a] at [2007-11-27 3:30:31]
# 1

I got it to work by using repaint() and a paint function instead like this:

class TestCanvas extends GameCanvas implements Runnable

{

Display display;

static int i;

public TestCanvas(Display d)

{

super(false);

display = d;

}

void start()

{

display.setCurrent(this);

repaint();

run();

}

public void run()

{

Graphics g = getGraphics();

while (true)

{

i++;

repaint();

try

{

Thread.sleep(10);

}

catch (InterruptedException ie)

{}

}

}

public void paint(Graphics g)

{

g.setColor(255, 255, 255);

g.fillRect(0, 0, getWidth(), getHeight());

g.setColor(0, 0, 0);

g.drawString("This is a test", 0, 0, 0);

g.drawString(i + "", 0, 20, 0);

}

}

The problem now is that when I press the exit button, it takes a few seconds to exit.

mmiikkee13a at 2007-7-12 8:33:33 > top of Java-index,Java Mobility Forums,Java ME Technologies...