Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android getchars()序列按1字节关闭_Android_Eclipse Adt - Fatal编程技术网

Android getchars()序列按1字节关闭

Android getchars()序列按1字节关闭,android,eclipse-adt,Android,Eclipse Adt,我设置了一个getchars()调用的测试示例,返回的字节按1的顺序排列 byte [] readBufA = new byte [] {1,2,3,4,5,6,7}; // Test array 然后我运行getchar,结果为1 String strIncom = new String(readBufA, 0, 7); // create string from bytes array String strIncom = new String(readBuf, 0, msg.arg1);

我设置了一个
getchars()
调用的测试示例,返回的字节按1的顺序排列

byte [] readBufA = new byte [] {1,2,3,4,5,6,7}; // Test array
然后我运行getchar,结果为1

String strIncom = new String(readBufA, 0, 7); // create string from bytes array
String strIncom = new String(readBuf, 0, msg.arg1); // create string from bytes array

sb.append(strIncom); // append string
int counter = sb.length(); // Get length of string
if (counter == 7){

getChars(0,7,readBufA,0);


Log.d(TAG, "Data " + sb + "  Size  " + (char)readBuf[0] + " " + (char)readBuf[1] +
" " + (char)readBuf[2] + " " + (char)readBuf[3] + " " +(char)readBuf[4] + 
" " + (char)readBuf[5] + " " + (char)readBuf[6] +" " + (char)readBuf[7]+ " " + counter); // receive massage

log.d
返回(2,3,4,5,6,7,-,-,7)计数器正确,但看不到正确的返回值是否
readBufA
readBuf
相同?您在问题中定义了
readBufA
。但是,
Log.i(…)
reads
readBuf
。Typo、readBuf和readBufA是相同的。另外,
(char)readBuf[7]
会抛出一个
ArrayIndexOutOfBoundsException
,因为
readBuf的大小是7。尝试使用
byte[]readBufA=newbyte[]{49,50,51,52,53,34,55}。输出将是
1,2,3,4,5,6,7
。我执行了测试以解决从字符串到字节[]的数据交叉问题。该建议确实解决了序列问题,但当我运行原始代码(删除测试)以附加数据时,我又回到了同样的问题。收到的每个字节都会将sb.append(strIncom)存储在字符串中,直到总共收到7个字节。然后将log.d(2,3,4,5,6,7,X,7)的结果转换回字节[]