2011-03-10 71 views
0

爲什麼Eclipse開發環境會抱怨android Bluetooth Connecting as client ConnectThread example中的private修飾符無效?私人班級可以有公共成員嗎?錯誤消息是:Android藍牙ConnectThread示例錯誤?

非法類修飾符 ConnectThread;只允許公開,抽象, 和final。

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) { } 
    } 
} 

回答

1

你在單獨一個文件有這個?這隻有在它是另一個班級的成員的班級時纔有效。

+0

是的。謝謝。 – jacknad 2011-03-10 21:54:14