package com.example.azezer0.demoanimatior; import android.animation.ObjectAnimator; import android.animation.PropertyValuesHolder; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.View; import android.view.Menu; import android.view.MenuItem; import android.widget.ImageView; public class MainActivity extends AppCompatActivity { private ImageView iv; private ObjectAnimator checkAnimator; private PropertyValuesHolder propertyValueScaleX; private PropertyValuesHolder propertyValueScaleY; private PropertyValuesHolder propertyValueScaleAlpha; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); iv = (ImageView) findViewById(R.id.iv); initAnimator(); iv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { checkAnimator.start(); } }); } private void initAnimator() { checkAnimator = new ObjectAnimator(); propertyValueScaleX = PropertyValuesHolder.ofFloat("scaleX", 0.0f, 1.0f); propertyValueScaleY = PropertyValuesHolder.ofFloat("scaleY", 0.0f, 1.0f); propertyValueScaleAlpha = PropertyValuesHolder.ofFloat("alpha", 0.0f, 1.0f); checkAnimator.ofPropertyValuesHolder(iv, propertyValueScaleAlpha, propertyValueScaleX, propertyValueScaleY).setDuration(2000).start(); } }进入页面时,是正常播放的,为什么触动点击事件,就报错。
Process: com.example.azezer0.demoanimatior, PID: 4361 java.lang.NullPointerException: Attempt to get length of null array at android.animation.ValueAnimator.initAnimation(ValueAnimator.java:534) at android.animation.ObjectAnimator.initAnimation(ObjectAnimator.java:880) at android.animation.ValueAnimator.setCurrentFraction(ValueAnimator.java:610) at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:589) at android.animation.ValueAnimator.start(ValueAnimator.java:1106) at android.animation.ValueAnimator.start(ValueAnimator.java:1117) at android.animation.ObjectAnimator.start(ObjectAnimator.java:852) at com.example.azezer0.demoanimatior.MainActivity$1.onClick(MainActivity.java:33) at android.view.View.performClick(View.java:5198) at android.view.View$PerformClick.run(View.java:21147) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)######搞定了######是怎么回事
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。