0

(Newbie's problem) The snippet of my code looks like:

    RotateAnimation rotateAnimation= (RotateAnimation) AnimationUtils
                .loadAnimation(MainActivity.this,R.anim.clockwise_anim);

and the clockwise_anim.xml located in res/anim looks like:

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <rotate xmlns:android="http://schemas.android.com/apk/res/android"
        android:fromDegrees="0"
        android:toDegrees="360"
        android:pivotX="50%"
        android:pivotY="50%"
        android:duration="5000" >
    </rotate>
</set>

and I've got an error excactly on this snippet above: java.lang.ClassCastException:

android.view.animation.AnimationSet cannot be cast to android.view.animation.RotateAnimation

I saw such code many times and I don't get what goes wrong in my case. Any suggestion? Thanks in advance!

ploponstack
  • 93
  • 1
  • 5
  • *I saw such code many times* where? Obviously you cannot cast object of type RotateAnimation to AnimationSet. It's basic OOP rule. As AnimationSet is not derived from RotateAnimation. – Selvin Jun 28 '17 at 22:10
  • For example:(https://stackoverflow.com/questions/8959069/how-to-rotate-textview-90-degrees-and-display) – ploponstack Jun 28 '17 at 22:12
  • Not true as root XML in that case is rotate not set. Also answer is bad as there is no need to cast at all... As loadAnimation returns Animation and setAnimation take Animation as parameter. – Selvin Jun 28 '17 at 22:13
  • Ok, I didn't suppose it could be the problem. It's my first time with animation. Many thanks for your time – ploponstack Jun 28 '17 at 22:15
  • Remove cast and replace type to Animation... – Selvin Jun 28 '17 at 22:16

0 Answers0