This is the Java code for creating an alpha animator object.
ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(myView, "alpha", 0.5f, 0f);
This is the Kotlin code for doing the same.
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. Could not find property setter method setAlpha on java.lang.Void more
Despite the IDE is giving this error, but I am still able to compile and run it. Any idea why it's giving this error in Kotlin and how to get rid of this error warning?
This happens because your myView
has nullable type, like View?
.
To get rid of this error convert your view to a non-null type (myView!!
):
val objectAnimator = ObjectAnimator.ofFloat(myView!!, "alpha", 0.5f, 0f)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With