Skip to content

Commit 1041bfd

Browse files
author
sabrinachen321
committed
fix a null pointer crash issue
1 parent 182f621 commit 1041bfd

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

0 Bytes
Binary file not shown.

SerialPortLibrary/src/main/java/com/kongqw/serialportlibrary/thread/SerialPortReadThread.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,13 @@ public void run() {
2929

3030
while (!isInterrupted()) {
3131
try {
32+
Log.i(TAG, "run: ");
33+
while (mInputStream != null && mInputStream.available() == 0) {
34+
Log.i(TAG, "Input stream length is 0");
35+
}
3236
if (null == mInputStream) {
3337
return;
3438
}
35-
36-
Log.i(TAG, "run: ");
37-
while (mInputStream.available() == 0) {
38-
// Do nothing
39-
}
4039
Thread.sleep(750);
4140
int size = mInputStream.read(mReadBuffer);
4241

@@ -54,7 +53,7 @@ public void run() {
5453
} catch (IOException e) {
5554
e.printStackTrace();
5655
return;
57-
} catch (InterruptedException e) {
56+
} catch (Exception e) {
5857
e.printStackTrace();
5958
}
6059
}

0 commit comments

Comments
 (0)