这是我与 bluecove 合作的第一个项目,我什至在开始之前就遇到了问题!
这是我的代码:
import java.io.IOException;
import java.util.ArrayList;
import bluecove;
/**
* Class that discovers all bluetooth devices in the neighbourhood and
displays their name and bluetooth address.
*/
public class BluetoothDeviceDiscovery implements DiscoveryListener {
// object used for waiting
private static Object lock = new Object();
// vector containing the devices discovered
public static ArrayList<RemoteDevice> devices;
public BluetoothDeviceDiscovery() {
devices = new ArrayList<RemoteDevice>();
}
// main method of the application
public static void main(String[] args) throws IOException {
//create an instance of this class
BluetoothDeviceDiscovery bluetoothDeviceDiscovery=new
BluetoothDeviceDiscovery();
//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, bluetoothDeviceDiscovery);
try {
synchronized(lock) {
lock.wait();
}
}
catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Device Inquiry Completed. ");
//print all devices in devices
int deviceCount=devices.size();
System.out.println(deviceCount);
}
}
}
我在第 3 行(惊喜,惊喜)上收到一个错误,告诉我一个 ';' 预料之中。
我知道我收到错误的真正原因是我没有正确导入 bluecove。
我下载了 bluecove jar,将其重命名并将文件添加到我的类路径中,认为我现在可以在我的 java 项目中导入和使用 bluecove。
我是否以错误的方式设置/导入 bluecove?我如何真正导入 bluecove 以便我可以在我的项目中使用蓝牙?
喵喔喔
汪汪一只猫
相关分类