Bluetooth 带有handleMessage的ClassCastException

Bluetooth 带有handleMessage的ClassCastException,bluetooth,handle,classcastexception,Bluetooth,Handle,Classcastexception,调试蓝牙连接接收字符串等的代码位。但是,似乎在代码行中得到了ClassCastException String read_Message = (String) msg.obj; 但是,如果我要使用我的前一段代码,收集字节并放入一个字符串中,则会运行,但不会收集一个字符串中的所有数据 我没有投下或错过什么,因为我知道我错过了什么,但看不见 如果需要更多的代码,我会放上去,其他的一切都正常 谢谢你的帮助 // The Handler that gets information back

调试蓝牙连接接收字符串等的代码位。但是,似乎在代码行中得到了
ClassCastException

String read_Message = (String) msg.obj;
但是,如果我要使用我的前一段代码,收集字节并放入一个字符串中,则会运行,但不会收集一个字符串中的所有数据

我没有投下或错过什么,因为我知道我错过了什么,但看不见

如果需要更多的代码,我会放上去,其他的一切都正常

谢谢你的帮助

     // The Handler that gets information back from the BluetoothService
    private final Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) 
        {
            switch (msg.what)
            {
            case MESSAGE_STATE_CHANGE:
//              if (D) Log.i(TAG, "MESSAGE_STATE_CHANGE: " + msg.arg1);
                switch (msg.arg1) 
                {
                case BluetoothService.STATE_CONNECTED:
                    break;
                case BluetoothService.STATE_CONNECTING:
                    //mTitle.setText(R.string.title_connecting);
                    break;
                case BluetoothService.STATE_LISTEN:
                case BluetoothService.STATE_NONE:
                    //mTitle.setText(R.string.title_not_connected);
                    break;
                }
                break;
            case MESSAGE_WRITE:
                //code to be entered here
                break;
            case MESSAGE_READ:
                //Previous code
                //byte[] read_Buf = (byte[]) msg.obj;
                // construct a string from the valid bytes in the buffer
                //String read_Message = new String(read_Buf, 0, msg.arg1);

                String read_Message = (String) msg.obj;

                if (mSmokeReadingArrayAdapter.isEmpty())
                    mSmokeReadingArrayAdapter.add("");

                mAdapter_Text.set(0, mAdapter_Text.get(0).toString() + read_Message);  

                mSmokeReadingArrayAdapter.notifyDataSetChanged();

                organiseString(read_Message);
                break;
            case MESSAGE_DEVICE_NAME:
                //code to be entered here
                break;
            case MESSAGE_TOAST:
                Toast.makeText(getApplicationContext(), msg.getData().getString(TOAST), Toast.LENGTH_SHORT).show();     // shows 'alert' messages
                break;
            }
        }
    };

问题解决了。这与蓝牙服务代码有关,该代码被定义为字节数组而不是字符串