Null problem in okta authorized request call from an android app

I took the android app that can be downloaded when a native app is created in okta. In the authorized fragment, I’m trying to call my okta protected api that runs in a spring boot app:

private fun callMyApi() {

val uri: Uri = Uri.parse("https://myserv.com/myapi/endpoint")
val properties = hashMapOf<String, String>()
val postParameters: HashMap<String, String> = HashMap()

sessionClient?.run {
    authorizedRequest(uri,
        null,
        null,
        ConnectionParameters.RequestMethod.GET,
        object : RequestCallback<JSONObject, AuthorizationException?> {
            override fun onSuccess(result: JSONObject) {
                info_view.text = "it worked!!!"
                Snackbar.make(info_view, getString(R.string.success), Snackbar.LENGTH_SHORT)
                    .show()
            }

            override fun onError(
                error: String,
                exception: AuthorizationException?
            ) {
                info_view.text = "it did not work screwed:"
                Snackbar.make(info_view, getString(R.string.error), Snackbar.LENGTH_SHORT)
                    .show()
            }
        })
}

}

However, I keep on getting the following error, independent of whether I put empty collections instead of the two nulls or not:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.okta.oidc, PID: 8824
    java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter error
        at com.okta.oidc.fragments.AuthorizedFragment$callMyStravaApi$$inlined$run$lambda$1.onError(Unknown Source:2)
        at com.okta.oidc.fragments.AuthorizedFragment$callMyStravaApi$$inlined$run$lambda$1.onError(AuthorizedFragment.kt:117)
        at com.okta.oidc.clients.sessions.SessionClientImpl.lambda$null$17(SessionClientImpl.java:136)
        at com.okta.oidc.clients.sessions.-$$Lambda$SessionClientImpl$DCnATHgD-WNX9YAwRxWuhF6ZLKg.run(Unknown Source:4)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
I/Process: Sending signal. PID: 8824 SIG: 9
Disconnected from the target VM, address: 'localhost:60989', transport: 'socket'

What could be the reason? How can I avoid this error?
I have also noticed that this method is deprecated, what other method should I call?

@advii Can you please add the details for the Okta sdk you referred? What is the version you are using? Is there a link?

Hi Lijia, sorry - the problem has been solved by exchanging error: String with error: String?

@advii It is glad to know the issue is resolved. So the solution is adding an error handling?

well the example code was Java, when I automatically migrated it to kotlin it did not get the hint that the error string might be null.

@advii I see. you meant it does not contains the null check right? Do you have the link for the sample code?

Hi Lijia,
it’s rather easy:

the sample you publish in the quick start for android:

    sessionClient.authorizedRequest(uri, properties, postParameters, HttpConnection.RequestMethod.POST,
        new RequestCallback<JSONObject, AuthorizationException>() {
            @Override
            public void onSuccess(@NonNull JSONObject result) {
                //handle JSONObject result.
            }

            @Override
            public void onError(String error, AuthorizationException exception) {
                //handle error
            }
    });

the second method has been translated automatically to kotlin in Intellijas

                override fun onError(
                    error: String,
                    exception: AuthorizationException?

but it has to be

                override fun onError(
                    error: String?,
                    exception: AuthorizationException?

No problem on the Okta side.

@advii Ok. I see. Thanks for the clarification. Then I’ll close this topic.