简体   繁体   English

找不到属性设置器方法setAlpha

[英]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.

相关问题 休眠映射-在类中找不到属性名称的设置器 - hibernate mapping - Could not find a setter for property name in class 骆驼路线测试:找不到合适的属性设置器: - Camel route test: Could not find a suitable setter for property: PropertyNotFoundException:找不到设置器 - PropertyNotFoundException: Could not find a setter 错误:找不到符号方法 setAlpha(float)。 setAlpha() 不适用于具有偏移量的数组 - Error: cannot find symbol method setAlpha(float). setAlpha() is not working on Array with offset 无法读取 JSON:属性的设置器定义冲突 - Could not read JSON: Conflicting setter definitions for property 在没有名为“类型”的属性的类中,我得到org.hibernate.PropertyNotFoundException:在类中找不到属性类型的设置方法 - In class without a property called “type” I get org.hibernate.PropertyNotFoundException: Could not find a setter for property type in class HIbernate映射异常:PropertyNotFoundException:找不到setter - HIbernate Mapping Exception: PropertyNotFoundException: Could not find a setter org.hibernate.PropertyNotFoundException:无法找到0的setter - org.hibernate.PropertyNotFoundException: Could not find setter for 0 为什么默认方法不被识别为属性(getter/setter)? - why default method not recognized as property(getter/setter)? 如何使用属性名称识别设置方法? - How to identify setter method using property name?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM