使用valueAnimator时,PropertyValuesHolder.setupSetterAndGetter中的NullPointerException / NoSuchMethodException,Android4.0

时间:2017-03-06 07:12:21

标签: android

我使用方法getHeight()和setHeight(int)创建了一个私有静态内部类ViewWrapper,并将其用作ValueAnimator的目标。 但是在Android 4.0中我得到NoSuchMethodException,导致异常。如果有人对此有任何想法并且可以帮助我,我们非常感激。

    PropertyValuesHolder: Can't find native method using JNI, use reflectionjava.lang.NoSuchMethodError: no method with name='setHeight' signature='(I)V' in class Lvc$a;
    PropertyValuesHolder: Couldn't find setter/getter for property height with value type int
    PropertyValuesHolder: Couldn't find no-arg method for property height: java.lang.NoSuchMethodException: getHeight []

    java.lang.NullPointerException
    at android.animation.PropertyValuesHolder.setupSetterAndGetter(PropertyValuesHolder.java:513)
    at android.animation.ObjectAnimator.initAnimation(ObjectAnimator.java:392)
    at android.animation.ValueAnimator.startAnimation(ValueAnimator.java:1052)
    at android.animation.ValueAnimator.access$400(ValueAnimator.java:49)
    at android.animation.ValueAnimator$AnimationHandler.handleMessage(ValueAnimator.java:616)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4424)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    at dalvik.system.NativeStart.main(Native Method)

private static class ViewWrapper {
    private View mTarget;

    public ViewWrapper(View target) {
        mTarget = target;
    }

    public int getWidth() {
        return mTarget.getLayoutParams().width;
    }

    public void setWidth(int width) {
        mTarget.getLayoutParams().width = width;
        mTarget.requestLayout();
    }

    public int getHeight(){
        return mTarget.getLayoutParams().height;
    }

    public void setHeight(int height) {
        mTarget.getLayoutParams().height = height;
        mTarget.requestLayout();
    }
}

0 个答案:

没有答案