我不斷收到空指標例外,我想查看回應是否存在,如果存在則將其列印出來。
if (responsePlace.result.opening_hours.weekday_text.isNotEmpty() ){
println("The response for place time " responsePlace.result.opening_hours.weekday_text[0].toString())}
uj5u.com熱心網友回復:
你可以試試這個:
responsePlace.let
{
when(it.isSuccessful) {
true -> println(""The response for place time " it.result.opening_hours.weekday_text[0].toString()")
false -> println("something went wrong!")
}
uj5u.com熱心網友回復:
isNullOrEmpty()在 kotlin 中使用方便的方法。
所以你的方法看起來像
if (!responsePlace.result.opening_hours.weekday_text.isNullOrEmpty()){
println("The response for place time " responsePlace.result.opening_hours.weekday_text[0].toString())}
照顧'!' 條件開始時的否定
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/381262.html
