Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
383 views
in Technique[技术] by (71.8m points)

android - Smart cast is impossible

I am trying to integrate UMP platform based on this documentation but I receive the following error. Could someone give me a suggestion on how to fix it?

Thank you in advance.

The bug is shown here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You are declaring consentInformation as a nullable field in line 14:

private var consentInformation: ConsentInformation? = null

As the field is mutable, its value could have changed between the execution of line 23 and line 24, so the compiler disallows you to refer to it without a null check.

In this specific case you could just change the field to be lateinit as you're assigning it in the onCreate method, which is executed first.

private lateinit var consentInformation: ConsentInformation

For more information about null safety in kotlin check this.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...