JakeWharton / ActionBarSherlock

[DEPRECATED] Action bar implementation which uses the native action bar on Android 4.0+ and a custom implementation on pre-4.0 through a single API and theme.
http://actionbarsherlock.com
Apache License 2.0
7.1k stars 3.53k forks source link

difference between ActionBarSherlock and NineOldAndroids for ObjectAnimator on Android <11 ? #942

Closed tonysms closed 11 years ago

tonysms commented 11 years ago

0 down vote favorite

I have a test activity which should do very simple task : inflate the view, and move it on the screen with ObjectAnimator.

This works perfectly with all devices (OS 2.2+ - OS4.2), if I use the NineOldAndroids library.

However, if I change the library to ActionBarSherlock (which supposes to have the same NineOldAndroid library inside), it works for OS 3.x and above, but it doesn't work for 2.2 and 2.3 devices. In this case it can not find the property and throws a Null Pointer exception (listed below).

Is this a bug, or I just have to consume both libraries (NineOldAndroids and ActionBarSherlock ) to resolve the issue?

I'm using the latest revisions of both libraries.

Here is the TestActivity :

public class TestActivity extends Activity {

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_test); RelativeLayout mainLayout = (RelativeLayout) findViewById(R.id.main_layout);

View testView = getLayoutInflater().inflate(R.layout.object_holder, null);

mainLayout.addView(testView);

AnimatorSet set = new AnimatorSet();
set.playTogether(
    ObjectAnimator.ofFloat(testView, "translationX", 100),
    ObjectAnimator.ofFloat(testView, "translationY", 100)
);
set.setDuration(0).start();

}

}

(Same thing happen, if I change "translationX" with "x" . )

Here is the exception (it's happening only if I use the library ActionBarSherlock on 2.2 and 2.3 devices) :

05-16 13:24:53.662: E/PropertyValuesHolder(2007): Couldn't find setter property translationX for RelativeLayout with value type float 05-16 13:24:53.662: E/PropertyValuesHolder(2007): RelativeLayout - Couldn't find no-arg method for property translationX: java.lang.NoSuchMethodException: getTranslationX 05-16 13:24:53.662: D/AndroidRuntime(2007): Shutting down VM 05-16 13:24:53.662: W/dalvikvm(2007): threadid=1: thread exiting with uncaught exception (group=0x4001d5a0) 05-16 13:24:53.672: E/AndroidRuntime(2007): FATAL EXCEPTION: main 05-16 13:24:53.672: E/AndroidRuntime(2007): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.testanimator/com.example.testanimator.TestActivity}: java.lang.NullPointerException 05-16 13:24:53.672: E/AndroidRuntime(2007): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1821) 05-16 13:24:53.672: E/AndroidRuntime(2007): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1842) 05-16 13:24:53.672: E/AndroidRuntime(2007): at android.app.ActivityThread.access$1500(ActivityThread.java:132) 05-16 13:24:53.672: E/AndroidRuntime(2007): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038) 05-16 13:24:53.672: E/AndroidRuntime(2007): at android.os.Handler.dispatchMessage(Handler.java:99) 05-16 13:24:53.672: E/AndroidRuntime(2007): at android.os.Looper.loop(Looper.java:150) 05-16 13:24:53.672: E/AndroidRuntime(2007): at android.app.ActivityThread.main(ActivityThread.java:4263) 05-16 13:24:53.672: E/AndroidRuntime(2007): at java.lang.reflect.Method.invokeNative(Native Method) 05-16 13:24:53.672: E/AndroidRuntime(2007): at java.lang.reflect.Method.invoke(Method.java:507) 05-16 13:24:53.672: E/AndroidRuntime(2007): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 05-16 13:24:53.672: E/AndroidRuntime(2007): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 05-16 13:24:53.672: E/AndroidRuntime(2007): at dalvik.system.NativeStart.main(Native Method) 05-16 13:24:53.672: E/AndroidRuntime(2007): Caused by: java.lang.NullPointerException 05-16 13:24:53.672: E/AndroidRuntime(2007): at com.actionbarsherlock.internal.nineoldandroids.animation.PropertyValuesHolder.setupSetterAndGetter(PropertyValuesHolder.java:515) 05-16 13:24:53.672: E/AndroidRuntime(2007): at com.actionbarsherlock.internal.nineoldandroids.animation.ObjectAnimator.initAnimation(ObjectAnimator.java:386) 05-16 13:24:53.672: E/AndroidRuntime(2007): at com.actionbarsherlock.internal.nineoldandroids.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:539) 05-16 13:24:53.672: E/AndroidRuntime(2007): at com.actionbarsherlock.internal.nineoldandroids.animation.ValueAnimator.start(ValueAnimator.java:929) 05-16 13:24:53.672: E/AndroidRuntime(2007): at com.actionbarsherlock.internal.nineoldandroids.animation.ValueAnimator.start(ValueAnimator.java:952) 05-16 13:24:53.672: E/AndroidRuntime(2007): at com.actionbarsherlock.internal.nineoldandroids.animation.ObjectAnimator.start(ObjectAnimator.java:364) 05-16 13:24:53.672: E/AndroidRuntime(2007): at com.actionbarsherlock.internal.nineoldandroids.animation.AnimatorSet.start(AnimatorSet.java:501) 05-16 13:24:53.672: E/AndroidRuntime(2007): at com.example.testanimator.TestActivity.onCreate(TestActivity.java:30) 05-16 13:24:53.672: E/AndroidRuntime(2007): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072) 05-16 13:24:53.672: E/AndroidRuntime(2007): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1785) 05-16 13:24:53.672: E/AndroidRuntime(2007): ... 11 more

SimonVT commented 11 years ago

You shouldn't use internal ABS classes. The NineOldAndroids included in ABS is a subset of the library that might have been changed to work for specific use-cases.