javax.bluetooth.BluetoothStateException when calling LocalDevice.getLocalDevice()

678 views
Skip to first unread message

C

unread,
Feb 9, 2009, 6:50:02 PM2/9/09
to bluecove-users
I took a Java class a while back and haven't programmed a lot in Java
recently, but I'm trying to run BlueCove "RemoteDeviceDiscovery.java".
I'm using NetBeans 6.5. When doing so, I encountered
BluetoothStateException after the call to LocalDevice.getLocalDevice.

Here is a snipet of the code:(I modified it slightly for debugging
purposes):
<code>
package com.intel.bluetooth.javadoc;


import java.io.IOException;
import java.util.Vector;

import javax.bluetooth.*;
import com.intel.bluetooth.*;

public class RemoteDeviceDiscovery {

...

try{
// boolean started = LocalDevice.getLocalDevice
().getDiscoveryAgent().startInquiry(DiscoveryAgent.GIAC, listener);

LocalDevice localDevice = null;
localDevice = LocalDevice.getLocalDevice();
} //try
catch (BluetoothStateException ex) {
System.err.println("ERROR: " + ex + ":
LocalDevice.getLocalDevice (Bluetooth system could not be
initialized.)");
System.err.flush();
return;
} // catch BluetoothStateException

...
--------------------------------------------------------------------------------------------
Run-time Output:

ERROR: javax.bluetooth.BluetoothStateException:
LocalDevice.getLocalDevice (Bluetooth system could not be
initialized.)

</code>

I had added "bluecove-2.1.0.jar" under "Project", "Project
Properties", "Libraries", "Compile", "Add JAR/Folder". Before running
the program, but the exception kept getting thrown.

After much searching, I solved the problem by putting the
"bluecove-2.1.0.jar" file in "C:\Program Files\Java\jdk1.6.0_11\jre\lib
\ext" folder.

My Java is perhaps a bit rusty, but does anyone know why the program
wouldn't work until I copied the bluecove jar to the jdk "ext" folder?





Mina Shokry

unread,
Feb 10, 2009, 10:11:59 AM2/10/09
to bluecove-users
first we need to know what OS you are using and what is your bluetooth
stack?

C

unread,
Feb 10, 2009, 2:56:49 PM2/10/09
to bluecove-users
I am running Windows Vista Home Premium on an HP DV2800t. I have a few
test programs, most of them seem to be using the Microsoft stack (from
program output: "BlueCove version 2.1.0 on winsock"). However, one of
them seems to using Widcomm stack (from program output: "BlueCove
version 2.1.0 on widcomm").

From Device Manager:

HP Integrated Module with Bluetooth 2.0 Wireless Technology
Manufacturer: Broadcom
Driver Provider: Broadcom
Driver Version: 6.2.6000.1
HCI version: 3.8489
LMP version: 3.16847

Microsoft Bluetooth Enumerator
Manufacturer: Microsoft
Driver Provider: Microsoft
Driver Version: 6.0.6001.18064




-----------------------------------------------------------------------------------------------------------

Vlad Skarzhevskyy

unread,
Feb 10, 2009, 3:03:28 PM2/10/09
to bluecov...@googlegroups.com
This is stage. Do you change the stack detection properties in application?
-Dbluecove.stack= or -Dbluecove.stack.first

By default on Vista Widcomm stack should be detected as Microsoft
stack "winsock" because Broadcom implemented Microsoft socket API on
Vista. (BTW This API do not have L2CAP to the best of my knowledge)
--
Vlad

C

unread,
Feb 11, 2009, 1:01:36 PM2/11/09
to bluecove-users
After reading some other posts, I've figured out why this was
occurring. I had copied some jar files
from the Sun WTK to jdk1.6.0_11\jre\lib\ext. I removed them and it
started working (in essence, I removed these
files from the classpath). I discovered the following in the process:


if "jsr82.jar" IS in "jdk1.6.0_11\jre\lib\ext" folder AND neither
"midpapi20.jar" NOR "midpapi21.jar" ARE
in "jdk1.6.0_11\jre\lib\ext" folder the following exception is seen:

output:
Exception in thread "main" javax.bluetooth.BluetoothStateException:
java.lang.NoClassDefFoundError: com/sun/kvem/jsr082/bluetooth/
DiscoveryAgentImpl
at javax.bluetooth.LocalDevice.getLocalDevice(LocalDevice.java:
100)
at RemoteDeviceDiscovery.main(RemoteDeviceDiscovery.java:23)

---------------------------------------------------------------------------------------------------------

if "jsr82.jar" AND ("midpapi20.jar" OR "midpapi21.jar") ARE in
"jdk1.6.0_11\jre\lib\ext" folder
the following exception is seen:

output:
Exception in thread "main" javax.bluetooth.BluetoothStateException
at com.sun.kvem.jsr082.bluetooth.LocalDeviceImpl.<init>
(LocalDeviceImpl.java:185)
at javax.bluetooth.LocalDevice.getLocalDevice(LocalDevice.java:
94)
at RemoteDeviceDiscovery.main(RemoteDeviceDiscovery.java:23)

C

unread,
Feb 11, 2009, 1:06:48 PM2/11/09
to bluecove-users
Your right. I forgot that I had changed the stack detection properties
when I was
troubleshooting:

In NetBeans 6.5 I had set the following:
File, Project Properties, Run, VM Options: -Dbluecove.stack=widcomm

That's why this particular program was using the widcomm stack.
Thanks
for the help. It's working great.

-----------------------------------------------------------------------------------------------------

Mina Shokry

unread,
Feb 13, 2009, 6:26:39 AM2/13/09
to bluecove-users
to get help on using BlueCove with NetBeans, review this wiki page.
http://code.google.com/p/bluecove/wiki/Using_BlueCove_with_NetBeans
Reply all
Reply to author
Forward
0 new messages