1

I have a small application written in Java on Windows and compiled with Java 1.6. The app uses SWT for its GUI. It works fine on Windows. But when I bring it over to my Mac, the application cannot be run. I keep getting a InvocationTargetException error on the console every time when I try to run it:

Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.UnsatisfiedLinkError: Cannot load 32-bit SWT libraries on 64-bit JVM
at org.eclipse.swt.internal.Library.loadLibrary(Library.java:197)
at org.eclipse.swt.internal.Library.loadLibrary(Library.java:174)
at org.eclipse.swt.internal.C.<clinit>(C.java:21)
at org.eclipse.swt.widgets.Display.<clinit>(Display.java:138)

I tried compiling my application in Java 1. 5 instead but I still get the same problem. I also tried to set the default Java AVM on my Mac to 1. 5 and 1.6 but both versions didn't work either. I am running on Mac OS X 1.5.8 I totally have no idea what's wrong since the application runs perfectly fine on my Windows machine.

Thanks for any help.

Carven
  • 14,988
  • 29
  • 118
  • 161

2 Answers2

0

See the underlying exception:

Cannot load 32-bit SWT libraries on 64-bit JVM

SWT has some native code (it is not pure Java), and the SWT binaries you have are for 32 bit OSX. Meanwhile, your JVM is a 64 bit VM.

Here's a discussion on the topic on Eclipse.org.

This post tells you where to get a 64 bit build.

Alternatively, this link tells you how to run the OSX VM in 32 bit mode:

Community
  • 1
  • 1
Dilum Ranatunga
  • 13,254
  • 3
  • 41
  • 52
  • In the link that tells how to run OSX VM in 32bit has something "resources" tag. I am not sure what is the resources tag referring to. Is it a file because I cannot find it. – Carven May 13 '11 at 20:46
0

The error message is pretty self-explanatory - you can't use 32-bit libraries with a 64-bit JVM.
Try the solution from http://technophi.com/2010/03/22/cannot-load-32-bit-swt-libraries-on-64-bit-jvm/ (add the -d32 switch to your command line)

Frank Schmitt
  • 30,195
  • 12
  • 73
  • 107
  • I tried to follow the link to add a -d32 argument but I get an error saying that the argument is invalid and cannot invoke virtual machine. – Carven May 13 '11 at 20:43