Bug 26624 - View.Background Property throws noSuchMethodError on Setter on API Level < 16
Summary: View.Background Property throws noSuchMethodError on Setter on API Level < 16
Status: RESOLVED ANSWERED
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 4.20.0
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2015-02-02 05:43 UTC by e.timm
Modified: 2015-03-02 14:40 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description e.timm 2015-02-02 05:43:56 UTC
Setting a drawable directly for the Background property of any view throws a noSuchMethodError with this ExceptionMessage: "no method with name='setBackground' signature='(Landroid/graphics/drawable/Drawable;)V' in class Landroid/view/View"

Using SetBackgroundDrawable(Drawable drawable) instead works fine however.

IMPORTANT: This has only occured on devices running Android 4.03. Devices with Android 4.12 and higher don't seem to have this problem.

StackTrace:

ex	{Java.Lang.NoSuchMethodError: Exception of type 'Java.Lang.NoSuchMethodError' was thrown.
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 
  at Android.Runtime.JNIEnv.GetMethodID (IntPtr kls, System.String name, System.String signature) [0x00066] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:162 
  at Android.Views.View.set_Background (Android.Graphics.Drawables.Drawable value) [0x00014] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.Views.View.cs:3835 
  at ???MyActivity???
 --- End of managed exception stack trace ---
java.lang.NoSuchMethodError: no method with name='setBackground' signature='(Landroid/graphics/drawable/Drawable;)V' in class Landroid/view/View;
	at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1154)
	at android.app.Activity.performResume(Activity.java:4539)
	at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2434)
	at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2472)
	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1986)
	at android.app.ActivityThread.access$600(ActivityThread.java:123)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
	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)
}	Java.Lang.NoSuchMethodError
Comment 1 Jonathan Pryor 2015-03-02 14:40:51 UTC
> Setting a drawable directly for the Background property of any view throws a noSuchMethodError with this ExceptionMessage:
> "no method with name='setBackground' signature='(Landroid/graphics/drawable/Drawable;)V' in class Landroid/view/View"

The problem is in the error message: View.setBackground(Drawable) was added in API-16 (Android v4.1), while you're trying to use it in API-15 (Android v4.0.3). It doesn't exist prior to API-16:

http://developer.android.com/reference/android/view/View.html#setBackground(android.graphics.drawable.Drawable)

If you need to set the background on API-15, then use a method that exists on API-15 such as View.SetBackgroundDrawable().