Kotlin - IllegalArgumentException in overridden method

In Kotlin, I override these two Google login features:

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() } } } 

to check if the connection is connected to Google.

The problem is that sometimes when I fire a user account dialog that pops up when an activity starts

Like this:

dialog

I get an IllegalArgumentException with the following logcat

E / AndroidRuntime: FATAL EXCEPTION: main Process: com.dancam.subscriptions, PID: 6346 java.lang.RuntimeException: Error executing ResultInfo {who = null, request = 6783, result = 0, data = null} action {com .dancam.subscriptions / com.dancam.subscriptions.ActiveSubscriptions.Subscriptions_main}: java.lang.IllegalArgumentException: parameter specified as non-null is null: kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull method, data parameters at android .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) on and roid.os.Handler.dispatchMessage (Handler.java:102) on android.os.Looper.loop (Looper.java:154) at android.app.ActivityThread.main (ActivityThread.java:6186) in 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) Called: java.lang.IllegalArgumentException: parameter set as nonzero is null: kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull method, parameter data at com.dancam.subscriptions.ActiveSubscriptions.Subscriptions_main.onActivityResult (Subscriptions 0mcriptions.mt. app.Activity.dispatchActivityResult (Activity.java:6937) at android.app.A ctivityThread.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) on android.os.Handler.dispatchMessage (Handler.java:102) on android.os.Looper.loop (Looper.java:154) at android.app.ActivityThread.main (ActivityThread.java:6186 ) in java.lang.reflect.Method.invoke (own method) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:889) at com.android.internal.os.ZygoteInit.main (ZygoteInit .java: 779)

which points to the onActivityResult function.

I tried to change

 requestCode: Int 

to

 requestCode: Int? 

But then I obviously get the error, because the function is not the same as it is from the superclass.

How can i fix this?

+5
source share
1 answer

do you need to specify data as null , so what is data: Intent? , because data intent may be null when the action is canceled or the result is not sent

Failed to execute ResultInfo result {who = null, request = 6783, result = 0, data = null } in action Parameter specified as non-null is null :

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

Source: https://habr.com/ru/post/1273274/


All Articles