如何解决如何在异常处理程序中映射 proguard?
我实现了一个 Exeption Handler 来捕获应用程序上的所有异常。
class ExceptionHandler : Thread.UncaughtExceptionHandler {
private val LINE_SEParaTOR = "\n"
override fun uncaughtException(thread: Thread,exception: Throwable) {
val stackTrace = StringWriter()
exception.printstacktrace(PrintWriter(stackTrace))
val errorReport = StringBuilder()
errorReport.append("************ CAUSE OF ERROR ************\n\n")
errorReport.append(stackTrace.toString())
// Todo: Report log
}
}
我收到了一份 NPE 报告,如下所示。但我不知道它是什么,因为它被混淆了
java.lang.NullPointerException
at l.d(java-style lambda group:2)
at androidx.lifecycle.LiveData.b(LiveData.java:6)
at androidx.lifecycle.LiveData.c(LiveData.java:8)
at x.r.x.j(mutablelivedata.java:4)
at com.example.ui.Exampleviewmodel$b.i(Exampleviewmodel.kt:14)
at c0.k.j.a.a.g(ContinuationImpl.kt:3)
at v.a.g0.run(dispatchedTask.kt:15)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6746)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Exampleviewmodel 报错的那一行是这样的:
fun callAPI(requestBody: MyRequestBody): Job = viewmodelScope.launch {
try {
val response = repository.fetchAPI(requestBody)
if (response.isSuccessful) {
_responseBody.value = response.body()
} else {
val msg = "callAPI() ${response.code()}: ${response.message()} ${response.errorBody()!!.string()}"
when {
response.code() >= 500 -> {
_toastMsg.value = msg
}
}
}
} catch (e: java.lang.Exception) {
_toastMsg.value = "${e.toString()}"
}
}
@Parcelize
@Keep
data class MyRequestBody(
val aData: String,val bData: String,val cData: String,val dData: String,val eData: String,val fData: String,val gData: Int,val hData: String?,val iData: String?,val jData: String?,val kData: String?
):Parcelable{
override fun toString(): String {
return "${aData},${bData},${cData}..."
}
}
如何映射数据以便我可以看到它们的原始名称?哪个部分会导致 NPE? (我猜响应 perce 是空的?) 我不知道如何在应用程序以及 LiveData、mutablelivedata 上进行映射。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。