I have the code below working before, now compiler halts and marks both if statements and says:
'if' must have both main and 'else' branches if used as an expression
But as you see this is not an expression, but just a simple equality statement and a conditional statement next to it.
try {
val json_string = responseBody!!.string()
val jsonObject = JSONObject(json_string)
if (jsonObject.has("version")) {
val remoteVersion = jsonObject.getInt("version")
if (remoteVersion > BuildConfig.VERSION_CODE) {
handler.post {
showInstallNewVersionDialog()
}
}
}
} catch (e: Exception) {
e.message?.let { Log.e(Constants.TAG, e.message!!) }
}
The funny part is if I added empty else tags, it will run but will warn to remove empty else statements:
if (jsonObject.has("version")) {
val remoteVersion = jsonObject.getInt("version")
if (remoteVersion > BuildConfig.VERSION_CODE) {
handler.post {
showInstallNewVersionDialog()
}
} else {}
} else {}
Aucun commentaire:
Enregistrer un commentaire