gpt4 book ai didi

android - Kotlin - 覆盖方法中的 IllegalArgumentException

转载 作者:IT老高 更新时间:2023-10-28 13:37:08 25 4
gpt4 key购买 nike

在 Kotlin 中,我将覆盖这两个 Google 登录功能:

override fun onConnectionFailed(result: ConnectionResult) {
if (result.hasResolution()) {
try {
result.startResolutionForResult(this, RESOLVE_CONNECTION_REQUEST_CODE)
} catch (e: IntentSender.SendIntentException) {
// Unable to resolve, message user appropriately
}

} else {
val gaa = GoogleApiAvailability.getInstance()
gaa.getErrorDialog(this, result.errorCode, 0)
}
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
when (requestCode) {
RESOLVE_CONNECTION_REQUEST_CODE -> if (resultCode == Activity.RESULT_OK) {
mGoogleApiClient!!.connect()
}
}
}

检查与谷歌的连接是否失败。

问题是,有时,当我关闭包含用户帐户的对话框时,该对话框会在 Activity 启动时弹出

喜欢这个:

dialog

我得到一个带有以下 logcat 的 IllegalArgumentException

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.dancam.subscriptions, PID: 6346 java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=6783, result=0, data=null} to activity {com.dancam.subscriptions/com.dancam.subscriptions.ActiveSubscriptions.Subscriptions_main}: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter data at android.app.ActivityThread.deliverResults(ActivityThread.java:4126) at android.app.ActivityThread.handleSendResult(ActivityThread.java:4169) at android.app.ActivityThread.-wrap20(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1552) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6186) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779) Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter data at com.dancam.subscriptions.ActiveSubscriptions.Subscriptions_main.onActivityResult(Subscriptions_main.kt:0) at android.app.Activity.dispatchActivityResult(Activity.java:6937) at android.app.ActivityThread.deliverResults(ActivityThread.java:4122) at android.app.ActivityThread.handleSendResult(ActivityThread.java:4169)  at android.app.ActivityThread.-wrap20(ActivityThread.java)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1552)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:154)  at android.app.ActivityThread.main(ActivityThread.java:6186)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779) 

指向 onActivityResult 函数。

我尝试改变

requestCode: Int

requestCode: Int?

但是我显然得到了一个错误,因为该函数与其父类(super class)中的函数不同。

我该如何解决?

最佳答案

你需要提到 data 作为 null 所以 data: Intent? 因为 data Intent 可以是 null 当 Action 被取消或没有发送结果时

Failure delivering result ResultInfo{who=null, request=6783, result=0, data=null} to activity Parameter specified as non-null is null:

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
// ^^

关于android - Kotlin - 覆盖方法中的 IllegalArgumentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47226041/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com