程序代码片段如下:
private void sendMessage(String message) { // Check that we"re actually connected before trying anything if (mChatService.getState() != BluetoothChatService.STATE_CONNECTED) { Toast.makeText(getActivity(), R.string.not_connected, Toast.LENGTH_SHORT).show(); return; } // Check that there"s actually something to send if (message.length() > 0) { // Get the message bytes and tell the BluetoothChatService to write byte[] send = message.getBytes("GBK"); /*************error**************/ mChatService.write(send); // Reset out string buffer to zero and clear the edit text field mOutStringBuffer.setLength(0); mOutEditText.setText(mOutStringBuffer); } }
byte[] send = message.getBytes(“GBK”); 这一句报错;
原来是不带参数,这样子发出去的内容出错,大于0x7F的都发的不对,猜想是编码格式的问题,可是这个参数该怎么填呢,像上面这样写总是报错误。求指导!
解决方案
15
之前有碰過這樣的問題,記得當時本人是填 “UTF-8” !
10
一般都是用 utf-8 的啊,题主怎么样知道要用 GBK 的呢,试一下用 gb2312
15
用uft-8即可