Problema JAVA Bluetooth!

di il
3 risposte

Problema JAVA Bluetooth!

Ciao a tutti

Ho scritto un codice java che mi permette di rilevare i dispositivi bluetooth nelle vicinanze! Ma nel momento in cui lo lancio mi va in errore e non riesco a capirne il motivo!

Allego il sorgente:

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

import javax.bluetooth.DeviceClass;
import javax.bluetooth.DiscoveryAgent;
import javax.bluetooth.DiscoveryListener;
import javax.bluetooth.LocalDevice;
import javax.bluetooth.RemoteDevice;
import javax.bluetooth.ServiceRecord;
import javax.bluetooth.UUID;


public class BluetoothServiceDiscovery implements DiscoveryListener{

//object used for waiting
private static Object lock=new Object();

//vector containing the devices discovered
private static Vector vecDevices=new Vector();

private static String connectionURL=null;


public static void main(String[] args) throws IOException {

BluetoothServiceDiscovery bluetoothServiceDiscovery=new BluetoothServiceDiscovery();

//display local device address and name
LocalDevice localDevice = LocalDevice.getLocalDevice();
System.out.println("Address: "+localDevice.getBluetoothAddress());
System.out.println("Name: "+localDevice.getFriendlyName());

//find devices
DiscoveryAgent agent = localDevice.getDiscoveryAgent();

System.out.println("Starting device inquiry...");
agent.startInquiry(DiscoveryAgent.GIAC, bluetoothServiceDiscovery);

try {
synchronized(lock){
lock.wait();
}
}
catch (InterruptedException e) {
e.printStackTrace();
}


System.out.println("Device Inquiry Completed. ");

//print all devices in vecDevices
int deviceCount=vecDevices.size();

if(deviceCount <= 0){
System.out.println("No Devices Found .");
}
else{
//print bluetooth device addresses and names in the format [ No. address (name) ]
System.out.println("Bluetooth Devices: ");
for (int i = 0; i <deviceCount; i++) {
RemoteDevice remoteDevice=(RemoteDevice)vecDevices.elementAt(i);
System.out.println((i+1)+". "+remoteDevice.getBluetoothAddress()+" ("+remoteDevice.getFriendlyName(true)+")");
}
}

System.out.print("Choose the device to search for Obex Push service : ");
BufferedReader bReader=new BufferedReader(new InputStreamReader(System.in));

String chosenIndex=bReader.readLine();
int index=Integer.parseInt(chosenIndex.trim());

//check for obex service
RemoteDevice remoteDevice=(RemoteDevice)vecDevices.elementAt(index-1);
UUID[] uuidSet = new UUID[1];
uuidSet[0]=new UUID("1105",true);

System.out.println("\nSearching for service...");
agent.searchServices(null,uuidSet,remoteDevice,bluetoothServiceDiscovery);

try {
synchronized(lock){
lock.wait();
}
}
catch (InterruptedException e) {
e.printStackTrace();
}

if(connectionURL==null){
System.out.println("Device does not support Object Push.");
}
else{
System.out.println("Device supports Object Push.");
}
}


public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) {
//add the device to the vector
if(!vecDevices.contains(btDevice)){
vecDevices.addElement(btDevice);
}
}


allego anche il messaggio di errore:

Exception in thread "main" java.lang.NoClassDefFoundError: com/symbian/gcf/ConnectionEndPoint
at Plugin11.BluetoothServiceDiscovery.main(BluetoothServiceDiscovery.java:33)
Caused by: java.lang.ClassNotFoundException: com.symbian.gcf.ConnectionEndPoint
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more


Avete per caso dei suggerimenti!?! GRAZIE MILLE

3 Risposte

Devi accedere o registrarti per scrivere nel forum
3 risposte