# Tuesday, 03 December 2002
« Interfaces & the Verifier | Main | Bonaire »
SWT

I've been working on getting the SWT (the Eclipse windowing toolkit) examples to run. This mostly involved implementing a lot of JNI methods.

The examples now run, but they do run into the occasional random NullPointerException. Probably caused by a sneaky bug in the (un)managed C++ code.

Here is a statically compiled version ControlExample (including all the supporting DLLs needed).

Note that this will only run on Windows, because my JNI implementation is written in Managed C++ it will not run on Mono.

Some interesting findings:

  • SWT has a reference to the sun.awt.windows.WEmbeddedFrame class. What's that about?
  • In order to get the FileViewer example to run, I had to use the STAThread attribute on my main method. Boy I'm I glad I missed the whole COM thing (was busy doing Java). This just too lame.
  • Reflection.Emit does not support embedding resources in a module (lame!). I had to add resource support to ikvmc (and the VM) to get ControlExample to work, statically compiled, so I added initialized global public fields to the assembly and used System.Runtime.CompilerServices.RuntimeHelpers.InitializeArray to copy the field data to an array.
Tuesday, 03 December 2002 09:32:32 (W. Europe Standard Time, UTC+01:00)  #    Comments [10] Tracked by:
"free poker downloads online" (free poker downloads online) [Trackback]

Tuesday, 03 December 2002 03:18:31 (W. Europe Standard Time, UTC+01:00)

Do you plan to open this prject up at some point?
Zohar Melamed
Tuesday, 03 December 2002 03:19:21 (W. Europe Standard Time, UTC+01:00)

Are you thinking of openning this project up at some point ? ( getting more developers involved )
Zohar Melamed
Tuesday, 03 December 2002 04:08:59 (W. Europe Standard Time, UTC+01:00)

I would love to get other people involved. I'm accepting patches ;-) and if anyone is seriously interested in participating, I'd be more than willing to look into creating a SourceForge project.
Wednesday, 04 December 2002 00:28:25 (W. Europe Standard Time, UTC+01:00)

I just want to say thank you for taken up this challenge. It is very exciting to see the progress of this project. SWT sure has put IKVM through a major JNI test. Amazing!
Wednesday, 04 December 2002 16:01:03 (W. Europe Standard Time, UTC+01:00)

have you tried having the C++ compiler generate only managed code? Sergey on the mailing list posted a few pointers on how to convince the MC++ compiler to do so.
Miguel de Icaza
Thursday, 05 December 2002 12:17:43 (W. Europe Standard Time, UTC+01:00)

To Miguel: That would be pointless, the whole point of using MC++ is that it enables me to implement the *native* side of the Java Native Interface. It has to be unmanaged. That said, at some point in the future I will be investigating alternatives to MC++, probably using Marshal.GetUnmanagedThunkForManagedMethodPtr.
Friday, 06 December 2002 11:59:59 (W. Europe Standard Time, UTC+01:00)

Hi-


I was very interested to see your work with SWT, but the ControlExample.exe throws the following exception right at startup:


Unhandled Exception: System.NullReferenceException: Object reference not set to
an instance of an object.
at LocalRefStruct.UnwrapLocalRef(IntPtr localref)
at JNIEnv.UnwrapRef(JNIEnv* , _jobject* o)
at JNIEnv.InvokeHelper(JNIEnv* , _jobject* object, _jmethodID* methodID, jval
ue* args)
at JNIEnv.CallIntMethodA(JNIEnv* , _jobject* obj, _jmethodID* methodID, jvalu
e* args)
at org.eclipse.swt.internal.win32.OS.EnableWindow(Int32 , Boolean )
at org.eclipse.swt.widgets.Control.setEnabled(Boolean )
at org.eclipse.swt.examples.controlexample.DialogTab.createControlWidgets()
at org.eclipse.swt.examples.controlexample.Tab.createTabFolderPage(TabFolder
)
at org.eclipse.swt.examples.controlexample.ControlExample..ctor(Composite )
at org.eclipse.swt.examples.controlexample.ControlExample.main(String[] )


I also tried to compile the swt AddressBook example using ikvmc which generated the following error:


D:projectssample-projectsclasses>ikvmc C:j2sdk1.4.1jrelibjce.jar C:j2sdk1.4.1jrelibrt.jar D:projectssample-projectslibswt.jar -reference:c:ikvmbinclasspath.dll -out:Test.exe -target:exe
-main:org.eclipse.swt.examples.addressbook.AddressBook
Parsing class files
Constructing compiler
Loading remapped types
Compiling class files (1)
java.lang.VerifyError: Cannot inherit from final class


Could you possibly point me in the right direction on what I am doing incorrectly. Thanks.


Chris Whelan

Chris Whelan
Friday, 06 December 2002 00:00:08 (W. Europe Standard Time, UTC+01:00)

Hi-


I was very interested to see your work with SWT, but the ControlExample.exe throws the following exception right at startup:


Unhandled Exception: System.NullReferenceException: Object reference not set to
an instance of an object.
at LocalRefStruct.UnwrapLocalRef(IntPtr localref)
at JNIEnv.UnwrapRef(JNIEnv* , _jobject* o)
at JNIEnv.InvokeHelper(JNIEnv* , _jobject* object, _jmethodID* methodID, jval
ue* args)
at JNIEnv.CallIntMethodA(JNIEnv* , _jobject* obj, _jmethodID* methodID, jvalu
e* args)
at org.eclipse.swt.internal.win32.OS.EnableWindow(Int32 , Boolean )
at org.eclipse.swt.widgets.Control.setEnabled(Boolean )
at org.eclipse.swt.examples.controlexample.DialogTab.createControlWidgets()
at org.eclipse.swt.examples.controlexample.Tab.createTabFolderPage(TabFolder
)
at org.eclipse.swt.examples.controlexample.ControlExample..ctor(Composite )
at org.eclipse.swt.examples.controlexample.ControlExample.main(String[] )


I also tried to compile the swt AddressBook example using ikvmc which generated the following error:


D:projectssample-projectsclasses>ikvmc C:j2sdk1.4.1jrelibjce.jar C:j2sdk1.4.1jrelibrt.jar D:projectssample-projectslibswt.jar -reference:c:ikvmbinclasspath.dll -out:Test.exe -target:exe
-main:org.eclipse.swt.examples.addressbook.AddressBook
Parsing class files
Constructing compiler
Loading remapped types
Compiling class files (1)
java.lang.VerifyError: Cannot inherit from final class


Could you possibly point me in the right direction on what I am doing incorrectly. Thanks.


Chris Whelan

Chris Whelan
Friday, 06 December 2002 00:02:50 (W. Europe Standard Time, UTC+01:00)

Sorry about the duplicate post; the form did not appear to have submitted. Also, the backslashes in the paths have been removed apparently because they were not escaped.
Chris Whelan
Saturday, 07 December 2002 08:16:52 (W. Europe Standard Time, UTC+01:00)

The NullReferenceException is (probably) caused by what I called "a sneaky bug in the (un)managed C++ code". If you start it several times, it should start up at some point. Or may be try a different system (if you have it). On my system it usually works, but every now and then I do get the exception.
Name
E-mail
Home page

I apologize for the lameness of this, but the comment spam was driving me nuts. In order to be able to post a comment, you need to answer a simple question. Hopefully this question is easy enough not to annoy serious commenters, but hard enough to keep the spammers away.

Anti-Spam Question: What method on java.lang.System returns an object's original hashcode (i.e. the one that would be returned by java.lang.Object.hashCode() if it wasn't overridden)? (case is significant)

Answer:  
Comment (HTML not allowed)  

Live Comment Preview