dispose() throwing exception?

Hi,

I have an application that runs on several handhelds. We are using the J9 runtime and the personal profile, and developing with eclipse.

Some of our devices are running Pocket PC 4.2. No problem there - the problems I describe below don't occur. However, one of our devices is running Windows CE 5. On this device, when I call dispose() on our frame, I'm getting the following exception stack trace:

Exception caught in event loop: java.lang.NullPointerException; event loop continuing ... java.lang.NullPointerException at org.eclipse.swt.widgets.Menu.releaseWidget(Unknown Source) at org.eclipse.swt.widgets.Widget.dispose(Unknown Source) at java.awt.MenuComponent._removeNotify(Unknown Source) at java.awt.MenuBar._removeNotify(Unknown Source) at java.awt.Frame._cleanUpShell(Unknown Source) at java.awt.Frame._removeNotify(Unknown Source) at java.awt.Component$RemoveNotifyRunnable.run(Unknown Source) at org.eclipse.swt.widgets.RunnableLock.run(Unknown Source) at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Unknown Source) at org.eclipse.swt.widgets.Display.runAsyncMessages(Unknown Source) at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source) at java.awt.BBToolkit.start(Unknown Source) at java.awt.BBToolkit$4.run(Unknown Source)

This is causing a problem, because when our application starts, we have native code that looks for an application window that already exists, and displays it (so we only get one instance running). But since dispose() is bugging out, the native code actually finds the leftovers of the previous window, but then can't display it - so the user can't open the app, and they have to soft-reset between runs of the app.

Oddly, using j9.exe throws the above exception, but must do some extra cleanup, because I can run the app again w/o a soft reset. But, I'd rather use j9w so my users don't have to see the java console.

Has anyone seen anything like this? Not exactly sure what I can do to prevent this from happening....maybe a native call to DestroyWindow would work...

Thanks,

Matt

[2109 byte] By [mqja] at [2007-10-3 4:28:51]
# 1

Assuming you're using Websphere Studio Device Developer from IBM (WSDD) (although i'm not sure you need to use specifically this) you can add a hook to each of your threads as they are created, and when system.exit(0) is called the j9 VM will close. You most likely as i have gotten, get an exception related to thread state but the J9 closes anyways. Here's the line of code

MyThread myThread = new MyThread();

com.ibm.oti.vm.VM.addShutdownHook(myThread);

Not sure if you have to add a hook to all the threads you create or just one, but i've added to all in my application.

This will fix the problem you have when you close your application once and try to restart it.

MBlissa at 2007-7-14 22:31:51 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2
Thanks for the response. I am using WSDD, but the shutdownHook doesn't seem to work in my case. Hopefully I can find some other way around it.
mqja at 2007-7-14 22:31:51 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3

So you added the hook to the thread, and when you called system.exit(0) you didn't receive an IllegalThreadStateException and the JVM didn't terminate? And you did add the hook to the thread right after you created it right? (Not sure if it matters if the thread is running or not before the hook needs to be added, but i'd test for both just to be sure).

MBliss

MBlissa at 2007-7-14 22:31:51 > top of Java-index,Java Mobility Forums,Java ME Technologies...