View.setBackground throws NoSuchMethodError

android, nosuchmethoderror, view

Solution

This method was introduced in API level 16, you are most probably running on an earlier one:

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

Use setBackgroundDrawable()

Problem

The following code: ``` View inflate = inflater.inflate(R.layout.page, null); Drawable img = getResources().getDrawable((Integer) (item.get("img"))); inflate.findViewById(R.id.page_img).setBackground(img); ``` produces the following error: `java.lang.NoSuchMethodError: android.view.View.setBackground` I have no idea why. I already tried the setBackground with `R.drawable.img` but I get the same error.

Original source

Related problems