Java AWT and Bluetooth RFCOMM
Java AWT and Bluetooth RFCOMM
- Subject: Java AWT and Bluetooth RFCOMM
- From: John Goodman <email@hidden>
- Date: Fri, 17 Dec 2004 09:40:18 -0500
I am trying to add Bluetooth RFCOMM connectivity to an existing Java
application. The Java app uses AWT for the GUI and a jnilib native
library for traditional serial port access.
I have based my code on Apple's JNI Example which calls a dylib from a
JNI library. (
http://developer.apple.com/samplecode/JNISample/JNISample.html ) I have
gotten as far as putting up the Bluetooth device selector controller
but I have quickly run into threading problems. When I click on the
"Search" button of the dialog, I get a "<NSObjectInaccessibleException>
NSDistantObject access attempted from another thread"
I have been cautioned about the threading limitations of Bluetooth. I
understand that Bluetooth must run in a single thread, and that the UI
must run in the main thread. What I don't understand is *how* to make
my Bluetooth code run in the main thread. Since the BT code is in a
dylib called from a jnilib I don't even know if it is possible.
In an earlier stab at a solution, I tried using the Java Objective-C
bridge, basing my code on the sample provided at
http://www.montagetech.com/developer_bridget.html In that case, I also
got a threading error - "Apple AWT Java VM was loaded on first thread
-- can't start AWT."
I gave up that approach because I was already unhappy with the
workarounds required to get Xcode over the bridge. Also, Apple has a
Q&A cautioning against mixing AWT and Cocoa Java which recommends using
JNI. ( http://developer.apple.com/qa/qa2001/qa1342.html ) But if the
bridge is ultimately more promising than JNI, I'll pursue it, assuming
that someone can tell me how to avoid the AWT error I'm faced with now.
I'm hoping there's at least one Java AWT/Bluetooth/Java Objective-C
bridge/threading expert out there who can solve problems like this in
his sleep. Or at least, someone who knows more about this than me,
which is sure to be a significantly larger group.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Bluetooth-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden