代码之家  ›  专栏  ›  技术社区  ›  NetworkStudent

错误:方法声明无效;Android需要返回类型

  •  0
  • NetworkStudent  · 技术社区  · 7 年前

    public sendReceive (BluetoothSocket socket){
            bluetoothSocket=socket;
            InputStream tempIn =null;
            OutputStream tempOut=null;
    
            try {
                tempIn=bluetoothSocket.getInputStream();
                tempOut=bluetoothSocket.getOutputStream();
            } catch (IOException e) {
                e.printStackTrace();
    
            }
    
    
        }
    

    错误:方法声明无效;需要返回类型

    以及sendReceive的所有功能。

     private class  SendReceive extends Thread{
    
    
        private final BluetoothSocket bluetoothSocket;
        private final InputStream inputStream;
        private final OutputStream outputStream;
    
    
    
    
        public sendReceive (BluetoothSocket socket){
            bluetoothSocket=socket;
            InputStream tempIn =null;
            OutputStream tempOut=null;
    
            try {
                tempIn=bluetoothSocket.getInputStream();
                tempOut=bluetoothSocket.getOutputStream();
            } catch (IOException e) {
                e.printStackTrace();
    
            }
    
    
        }
    
    
        public void run(){
            byte[] buffer=new byte[1024];
            int bytes;
            while(true){
                try {
                    bytes=inputStream.read(buffer);
                    handler.obtainMessage(STATE_MESSAGE_RECEIVER,bytes,-1,buffer).sendToTarget();
                } catch (IOException e) {
                    e.printStackTrace();
    
                }
            }
    
        }
    
        public void write(byte[] bytes){
            try {
                outputStream.write(bytes);
            } catch (IOException e) {
                e.printStackTrace();
            }
    
        }
    

    1 回复  |  直到 7 年前
        1
  •  0
  •   Sagar    7 年前

    sendReceive SendReceive .

    InputStream inputStream &安培; OutputStream outputStream final