這是我與 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 以便我可以在我的項目中使用藍牙?
2 回答

喵喔喔
TA貢獻1735條經驗 獲得超5個贊
以防萬一有些不耐煩的人來這里快速復制和粘貼,這是我的進口清單:
import javax.bluetooth.BluetoothStateException;
import javax.bluetooth.DiscoveryAgent;
import javax.bluetooth.DiscoveryListener;
import javax.bluetooth.LocalDevice;
import javax.bluetooth.RemoteDevice;
import javax.bluetooth.UUID;

汪汪一只貓
TA貢獻1898條經驗 獲得超8個贊
前兩個import
語句告知 Java您在代碼中引用的IOException
和ArrayList
類的完整包路徑。
一旦您開始在代碼中使用 bluecove 類,您將需要添加一個或多個 import 語句,告訴 Java 這些類的完整包路徑。
添加回答
舉報
0/150
提交
取消