[英]Could not find property setter method setAlpha
This is the Java code for creating an alpha animator object. 这是用于创建alpha动画对象的Java代码。
ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(myView, "alpha", 0.5f, 0f);
This is the Kotlin code for doing the same. 这是Kotlin的相同代码。
val objectAnimator = ObjectAnimator.ofFloat(myView, "alpha", 0.5f, 0f)
After I converted above Java code to Kotlin, Android Studio is giving me a red error warning with the this message when hover over the line where the error occurs. 在将上述Java代码转换为Kotlin之后,当悬停在发生错误的行上方时,Android Studio会通过此消息向我发出红色错误警告。 Could not find property setter method setAlpha on java.lang.Void more
在java.lang.Void上找不到属性设置器方法setAlpha
Despite the IDE is giving this error, but I am still able to compile and run it. 尽管IDE给出了此错误,但是我仍然能够编译并运行它。 Any idea why it's giving this error in Kotlin and how to get rid of this error warning?
知道为什么它会在Kotlin中给出此错误,以及如何摆脱此错误警告吗?
This happens because your myView
has nullable type, like View?
发生这种情况是因为您的
myView
具有可为null的类型,例如View?
. 。 To get rid of this error convert your view to a non-null type (
myView!!
): 要摆脱此错误,请将您的视图转换为非null类型(
myView!!
):
val objectAnimator = ObjectAnimator.ofFloat(myView!!, "alpha", 0.5f, 0f)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.