java - Android 蓝牙 ConnectThread 示例错误?

标签 java android bluetooth

为什么Eclipse开发环境报错android中的private修饰符无效Bluetooth Connecting as client ConnectThread example ?私有(private)类(class)可以有公共(public)成员吗?错误信息是:

Illegal modifier for class ConnectThread; only public, abstract, and final are permitted.

private class ConnectThread extends Thread {
    private final BluetoothSocket mmSocket;
    private final BluetoothDevice mmDevice;

    public ConnectThread(BluetoothDevice device) {
        BluetoothSocket tmp = null;
        mmDevice = device;
        try {
            tmp = device.createRfcommSocketToServiceRecord(MY_UUID);
        } catch (IOException e) { }
        mmSocket = tmp;
    }
    public void run() {
        mAdapter.cancelDiscovery();
        try {
            mmSocket.connect();
        } catch (IOException connectException) {
            try {
                mmSocket.close();
            } catch (IOException closeException) { }
            return;
        }
        manageConnectedSocket(mmSocket);
    }
    public void cancel() {
        try {
            mmSocket.close();
        } catch (IOException e) { }
    }
}

最佳答案

你有这个单独的文件吗?仅当一个类是另一个类的成员时,这才有效。

关于java - Android 蓝牙 ConnectThread 示例错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5265750/

相关文章:

java - 在Python中运行包含java命令的批处理文件

Java 三元运算符对泛型类型推断的影响

java - 嵌套类@Configuration中的spring Bean覆盖2.1.x @Bean创建失败 'A bean with that name has already been defined'

android - EditText 焦点丢失

android - 多个微调器和 onItemSelected

java - 代号一中工具栏中的无限旋转命令(或按钮)

android - 如何获取最新的 Room 版本?

bluetooth - CRC 低功耗蓝牙 4.2

android - 具有蓝牙 LE 外围功能的 Android 设备的市场份额?

iphone - GameKit在设备屏幕关闭或处于后台时保持连接状态