【发布时间】:2012-11-13 17:01:19
【问题描述】:
我有以下代码,我使用 ReadUnsignedByte() 函数但挂起并且不返回任何导致挂起应用程序的内容。我用了try catch但是没有响应,这种情况我该怎么办?
private int getEndOfSeqeunce(DataInputStream in, byte[] sequence) throws TimeoutException {
int seqIndex = 0;
byte c = -99;
for(int i=0; i < FRAME_MAX_LENGTH; i++) {
Log.v("DataInputStream", ""+in);
try {
c = (byte) in.readUnsignedByte(); // Stuck here ... No response at this line which hangs the Android application.
Log.v("C ::::::::UNSIGNE::readUnsignedByte::::::::", ""+c);
if(c == sequence[seqIndex]) {
seqIndex++;
if(seqIndex == sequence.length) return i + 1;
} else seqIndex = 0;
} catch (IOException e) {
e.printStackTrace();
i = FRAME_MAX_LENGTH;
Activity ac = (Activity) cox;
}
}
return -1;
}
【问题讨论】:
-
没有响应,它不打印任何东西,我试图记录它但它没有到达下一行。
-
datainputstream 包装的是什么? Log.v("数据输入流", ""+in);你没有打印出来吗?
-
为了确保您不会挂起您的应用程序:使用 AsyncTask :)
-
我使用了 AsyncTask,但它也会挂起 UI,因为我在等待 AsyncTask 的结果