Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException when the animation end #91

Closed
csr91706 opened this issue Feb 23, 2017 · 24 comments
Closed

NullPointerException when the animation end #91

csr91706 opened this issue Feb 23, 2017 · 24 comments
Labels

Comments

@csr91706
Copy link

csr91706 commented Feb 23, 2017

i have download your demo,and run it ,but when i touch one list item,it is broken.and show the NullPointerException . i found if i set repeat 1,it is ok,but if i set others ,it is broken.
q5ax3gc wryoddwl 70k ly

@csr91706 csr91706 changed the title NullPointerException NullPointerException when the animation end Feb 23, 2017
@daimajia
Copy link
Owner

The demo apk, downloaded from the readme file?

BTW. Which Android version you are using?

@wzgl5533
Copy link

me too. But version is 5.0+, it's OK . Why ?

@wzgl5533
Copy link

我在5.0版本,没有问题,在4.2测试报错和楼上一样,请问作者这是什么原因?

@mandeep-vratesh
Copy link

mandeep-vratesh commented Mar 6, 2017

I tried it on 4.4.4 and 4.1.1, it is giving the same exception. Though it doesn't crash when I try the example provided at the top right.

@daimajia
Copy link
Owner

daimajia commented Mar 8, 2017

@wzgl5533 @mandeep-vratesh Which lib version you are trying?

@wzgl5533
Copy link

wzgl5533 commented Mar 8, 2017

I try it according to your step,Do you test your code on version 4+?

@mandeep-vratesh
Copy link

@daimajia I followed the readme. So it's 2.2

@daimajia
Copy link
Owner

daimajia commented Mar 10, 2017

@wzgl5533 @mandeep-vratesh Could any one show me the code context? For helping me to address the problem.

@mandeep-vratesh
Copy link

@daimajia here is my project that I am working on.

@Lakedaemon
Copy link

Lakedaemon commented Mar 10, 2017

Got the same problem with this (on a Samsung Galaxy S3 with android 4.4):
compile 'com.daimajia.androidanimations:library:2.2@aar'
compile 'com.daimajia.easing:library:2.0@aar'

YoYo.with(Techniques.Shake)
                            .duration(700)
                            .repeat(-1)
                            .delay(3000)
                            .playOn(download)

where download is a Button

I got a NPE that crashs my app after 2 shakes (at the end of the second shake ?)
java.lang.NullPointerException
    at  android.animation.AnimatorSet$AnimatorSetListener.onAnimationEnd (AnimatorSet.java : 797)
    at  android.animation.ValueAnimator.endAnimation (ValueAnimator.java : 1056)
    at  android.animation.ValueAnimator.access$400 (ValueAnimator.java : 50)
    at  android.animation.ValueAnimator$AnimationHandler.doAnimationFrame (ValueAnimator.java : 644)
    at  android.animation.ValueAnimator$AnimationHandler.run (ValueAnimator.java : 660)
    at  android.view.Choreographer$CallbackRecord.r un (Choreographer.java : 813)
    at  android.view.Choreographer.doCallbacks (Choreographer.java : 613)
    at  android.view.Choreographer.doFrame (Choreographer.java : 582)
    at  android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java : 799)
    at  android.os.Handler.handleCallback (Handler.java : 733)
    at  android.os.Handler.dispatchMessage (Handler.java : 95)
    at  android.os.Looper.loop (Lo oper.java : 146)
    at  android.app.ActivityThread.main (ActivityThread.java : 5679)
    at  java.lang.reflect.Method.invokeNativeNative Method
    at  java.lang.reflect.Method.invoke (Method.java : 515)
    at  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java : 1291)
    at  com.android.internal.os.ZygoteInit.main (ZygoteInit.java : 1107)
    at  dalvik.system.NativeStart.mainNative Method

@Lakedaemon
Copy link

Could this be related to this issue (observed in another library) ?
KeepSafe/TapTargetView#121

Basically : on some devices, touching the view hierarchy in on Animation End make it throw an Exception
because of a buggy ViewGroup implementation ?

@microcian
Copy link

I guess you are passing a null object. and may be the problem with repeat() function because after first time when you came again the object is null ...

@CValeron
Copy link

Anyone found a solution to this ?

@Lakedaemon
Copy link

Lakedaemon commented Mar 14, 2017

The screen doesn't change when the issue appears :
I can reproduce it 100% : I inflate the view, I start the infinite animation on a view that is layed out and not null, I don't touch the view (I just wait for the issue to happen) and... the app crashes

I grepped some code and I think that the issue and the stack trace leads to the folowing version of AnimatorSet (android 4.4.4 r_1) : http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.4.4_r1/android/animation/AnimatorSet.java#AnimatorSet

Node animNode = mAnimatorSet.mNodeMap.get(animation) at line 796 returns null and then line 797 throws

792         @SuppressWarnings("unchecked")
793         public void More ...onAnimationEnd(Animator animation) {
794             animation.removeListener(this);
795             mPlayingSet.remove(animation);
796             Node animNode = mAnimatorSet.mNodeMap.get(animation);
797             animNode.done = true;
798             if (!mTerminated) {
799                 // Listeners are already notified of the AnimatorSet ending in cancel() or
800                 // end(); the logic below only kicks in when animations end normally
801                 ArrayList<Node> sortedNodes = mAnimatorSet.mSortedNodes;
802                 boolean allDone = true;
803                 int numSortedNodes = sortedNodes.size();
804                 for (int i = 0; i < numSortedNodes; ++i) {
805                     if (!sortedNodes.get(i).done) {
806                         allDone = false;
807                         break;
808                     }
809                 }
810                 if (allDone) {
811                     // If this was the last child animation to end, then notify listeners that this
812                     // AnimatorSet has ended
813                     if (mListeners != null) {
814                         ArrayList<AnimatorListener> tmpListeners =
815                                 (ArrayList<AnimatorListener>) mListeners.clone();
816                         int numListeners = tmpListeners.size();
817                         for (int i = 0; i < numListeners; ++i) {
818                             tmpListeners.get(i).onAnimationEnd(mAnimatorSet);
819                         }
820                     }
821                     mAnimatorSet.mStarted = false;
822                     mAnimatorSet.mPaused = false;
823                 }
824             }
825         }

As Said before, the only animation code I'm using is

YoYo.with(Techniques.Shake)
.duration(700)
.repeat(-1)
.delay(3000)
.playOn(download)

on a Button whose name is download and which is inflated, layed out and not null

@Lakedaemon
Copy link

investigating further : mNodeMap is mostly used in builders... and in the clone() method that is used to repeat the animation.

And it looks like they changed the implementation of clone() between 4.4.4_r1 and 5.1.0_r1
http://grepcode.com/file_/repository.grepcode.com/java/ext/com.google.android/android/5.1.0_r1/android/animation/AnimatorSet.java/?v=diff&id2=4.4.4_r1

So there might be something wrong with the clone() method... for 4.4.4

@Lakedaemon
Copy link

Lakedaemon commented Mar 15, 2017

A workaround for this issue is to handle the repeat process yourself,
for example with RxJava :

Observable.interval(2000, 3700, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread()).subscribe {
            YoYo.with(Techniques.Shake)
                    //.delay(3000)
                    .duration(700)
                    // .repeat(-1)
                    .playOn(button)
        }

I guess that a way fixto fix that would be to change the way Yoyo handles repetitions :
instead of using the clone() method of AnimatorSet in onanimationEnd() which looks unreliable,
store or implement a clone() method for the builder in the yoyo library and, at each repetition, create an animation from scratch from the builder

@daimajia
Copy link
Owner

@Lakedaemon Thanks for your information. I'll do some research on this issue, It's actually pretty annoying that the AnimatorSet has been set to final class descriptor... I have no idea why the made that.

@bitristan
Copy link

It seems that we could not use AnimatorSet.clone() method. I have an idea, we can setRepeatCount for each ValueAnimator which in AnimatorSet. Then play together will work as we expected.

@SirWellington
Copy link

bitmoji
Any updates on this?

@gsc1234567890woshishui
Copy link

一样还是崩溃!为啥不修复好可惜的一个项目没法用了

@mjal146
Copy link

mjal146 commented Jun 22, 2017

I have this problem too in android 4.4

@PaolinoAngeletti
Copy link

PaolinoAngeletti commented Jun 28, 2017

With repeat 1 the problem not appear..
but this is very strange.. at least with 1 it's usefull..

@daimajia
Copy link
Owner

daimajia commented Jul 17, 2017

Hi guys, sorry for my late reply, there was something terrible happened to my family two month ago, so I disappeared for a while. Anyway, This issue has been fixed, new version will be published to maven ASAP.

Thanks @Tinker-S .

@conghongjie
Copy link

could you tell me how to fix ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests