NoSuchMethodError when I use android.widget.RelativeLayout.setBackground

Daniel Diaz picture Daniel Diaz · Apr 16, 2013 · Viewed 12.9k times · Source

At android 4.2 my app works fine, but when I try to test it using android 4.0.4 I have this message error:

04-16 15:06:46.601: E/AndroidRuntime(3844): java.lang.NoSuchMethodError: android.widget.RelativeLayout.setBackground
    04-16 15:06:46.601: E/AndroidRuntime(3844):     at com.myapp.MainActivity.cambiarPagina(MainActivity.java:271)
    04-16 15:06:46.601: E/AndroidRuntime(3844):     at com.myapp.MainActivity.cambiarPagina(MainActivity.java:119)
    04-16 15:06:46.601: E/AndroidRuntime(3844):     at com.myapp.MainActivity.access$0(MainActivity.java:116)
    04-16 15:06:46.601: E/AndroidRuntime(3844):     at com.myapp.MainActivity$2.onClick(MainActivity.java:70)
    04-16 15:06:46.601: E/AndroidRuntime(3844):     at android.view.View.performClick(View.java:3524)
    04-16 15:06:46.601: E/AndroidRuntime(3844):     at android.view.View$PerformClick.run(View.java:14202)
    04-16 15:06:46.601: E/AndroidRuntime(3844):     at android.os.Handler.handleCallback(Handler.java:605)
    04-16 15:06:46.601: E/AndroidRuntime(3844):     at android.os.Handler.dispatchMessage(Handler.java:92)
    04-16 15:06:46.601: E/AndroidRuntime(3844):     at android.os.Looper.loop(Looper.java:137)
    04-16 15:06:46.601: E/AndroidRuntime(3844):     at android.app.ActivityThread.main(ActivityThread.java:4499)
    04-16 15:06:46.601: E/AndroidRuntime(3844):     at java.lang.reflect.Method.invokeNative(Native Method)
    04-16 15:06:46.601: E/AndroidRuntime(3844):     at java.lang.reflect.Method.invoke(Method.java:511)
    04-16 15:06:46.601: E/AndroidRuntime(3844):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:788)
    04-16 15:06:46.601: E/AndroidRuntime(3844):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
    04-16 15:06:46.601: E/AndroidRuntime(3844):     at dalvik.system.NativeStart.main(Native Method)

I use setBackgroud to add some animation, like this code

AnimationDrawable animation = new AnimationDrawable();
                                 animation.addFrame(getResources().getDrawable(R.drawable.d1), 200);
                                 animation.addFrame(getResources().getDrawable(R.drawable.dio), 1000);
                                 animation.addFrame(getResources().getDrawable(R.drawable.da1), 200);
 animation.setOneShot(true);
 view.setBackground(animation);
 view.post(new Starter(animation));

I have support library added to my project, and I don't know how solve this, any help will be apreciated!

Answer

dmon picture dmon · Apr 16, 2013

That was added in API 16, try setBackgroundDrawable()