Skip to content

Commit 583e8da

Browse files
committed
判空
1 parent d527d3c commit 583e8da

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

app/src/main/java/com/example/ivdemo/ClientActivity.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -589,18 +589,22 @@ class ClientActivity : AppCompatActivity(), IvClientCallback, OnEncodeListener {
589589
val responseResult = mVideoNativeInterface.sendClientCommand(clientId, cmd.toByteArray(), timeout)
590590
val res = String(responseResult)
591591
val jsonResult = JSONObject(res)
592-
val code = jsonResult.getInt("code")
593-
val msg = jsonResult.getString("errMsg")
594-
Log.d(TAG, "send client command: $cmd result: $res")
592+
var code = -1
593+
if (jsonResult.has("code")){
594+
code = jsonResult.getInt("code")
595595

596+
}
597+
var msg = ""
598+
if (jsonResult.has("errMsg")){
599+
msg = jsonResult.getString("errMsg")
600+
}
601+
Log.d(TAG, "send client command: $cmd result: $res")
596602
if (code != 0) {
597603
Log.e(TAG, "send client command error, code: $code, msg: $msg")
598604
}
599-
600605
return code
601606
} else {
602607
Log.w(TAG, "send client command error, cmd is null or empty")
603-
604608
return -1
605609
}
606610
}

0 commit comments

Comments
 (0)