|
課程設(shè)計單片機和安卓手機進(jìn)行藍(lán)牙通信,發(fā)送電壓數(shù)據(jù)到手機,恰好每次8位數(shù)據(jù)(1字節(jié))傳給上位機。采用以下代碼獲得16進(jìn)制字符輸出,以下是藍(lán)牙通信接收并顯示數(shù)據(jù)部分代碼- case Constants.MESSAGE_READ:
- // construct a string from the valid bytes in the buffer
- byte[] readBuf = (byte[]) msg.obj;
- String readMessage = new String(readBuf, 0, msg.arg1);
- mConversationArrayAdapter.add(mConnectedDeviceName + ": " + readMessage);
- break;
復(fù)制代碼 我想將字節(jié)數(shù)組數(shù)據(jù)轉(zhuǎn)換為十進(jìn)制,做進(jìn)一步計算,計算結(jié)果以十進(jìn)制打印輸出。代碼如下:
- case Constants.MESSAGE_READ:
- if (!msg.obj.equals(null)) {
- byte[] readBuf = (byte[]) msg.obj;
- for (int i = 0; i < readBuf.length; i++) {
- int[] a = new int[readBuf.length];
- a[i] = readBuf[i] * 5000 / 255;
- mConversationArrayAdapter.add(mConnectedDeviceName + ": ");
- System.out.print(a[i]);
- }
- }
- break;
復(fù)制代碼
上面的第二段代碼編譯無錯誤,但在手機上執(zhí)行后只顯示mConnectedDeviceName 和": ",a輸出為空白!
調(diào)試顯示以下error:com.example.android.bluetoothchat E/dalvikvm: Could not find class 'android.support.v4.app.ActivityCompat$SharedElementCallback23Impl',
第一次接觸JAVA編程,還請多多指教! |
|