M
M
motivation-maybe2021-01-01 00:07:08
Android
motivation-maybe, 2021-01-01 00:07:08

How to fix error when changing API level in Android Studio?

I decided to take on Android Studio for the first time and develop in this regard, respectively, a beginner.

I found an old ready-made project and edited it for myself, honing my skills, but...
When I change the API level from 28 to 30, I get an error:

project\app\src\main\java\com\name\appname\download .kt: (174, 39): Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type ClipData?

This field contains the following code:

view.ivLink.setOnClickListener(fun(view: View) {
            val clipBoardManager =
                context!!.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager

            val primaryClipData = clipBoardManager.primaryClip
(174)       val clip = primaryClipData.getItemAt(0).text.toString()

            etURL.text = Editable.Factory.getInstance().newEditable(clip)
            DownloadVideo(clip);
        })


Please tell me how to fix? I will be grateful.
The error is only on version 30 of the SDK, on ​​28 everything is fine.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolay Savelyev, 2021-01-01
@AgentSmith

Here is the solution:

Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type ClipData

Nullable is the first chapter in any Kotlin book. Go learn a language

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question