ClasscastException不能投射到线性布局的Button.widget.button上。

问题描述 投票:0回答:1
 Process: com.example.e_classroom, PID: 12427
    java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.Button
        at com.example.e_classroom.test_questions$3.onAnimationEnd(test_questions.java:116)
        at android.view.ViewPropertyAnimator$AnimatorEventListener.onAnimationEnd(ViewPropertyAnimator.java:1136)
        at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1171)
        at android.animation.ValueAnimator$AnimationHandler.doAnimationFrame(ValueAnimator.java:722)
        at android.animation.ValueAnimator$AnimationHandler.run(ValueAnimator.java:738)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:800)
        at android.view.Choreographer.doCallbacks(Choreographer.java:603)
        at android.view.Choreographer.doFrame(Choreographer.java:571)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:786)
        at android.os.Handler.handleCallback(Handler.java:815)
        at android.os.Handler.dispatchMessage(Handler.java:104)
        at android.os.Looper.loop(Looper.java:194)
        at android.app.ActivityThread.main(ActivityThread.java:5637)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

在这里发现了错误,谁能帮助这个如何解决这个错误呢?

        public void onAnimationEnd(Animator animation) {
            if(value==0) {
                try{
                    ((TextView)v).setText(data);
                    questindicator.setText(position+1+"/"+list.size());
                }catch (ClassCastException ex){
          // here 116 line no
      ((Button)v).setText(data);
                }
                v.setTag(data);
                playanimate(v, 1,data);
            }
        }
android-studio classcastexception
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.