Akshay
Akshay

Reputation: 6142

java.lang.NoSuchMethodError: setBackground()

In my app I'm trying to set a Bitmap Image to FrameLayout, where the image came from SQLite database. I'm decoding that image converting it into Drawable and then setting it as background to FrameLayout but it gives me Error like java.lang.NoSuchMethodError: android.widget.FrameLayout.setBackground()

    ByteArrayInputStream imageStream2= new ByteArrayInputStream(cardbackground);
Bitmap Imagebackground = BitmapFactory.decodeStream(imageStream2);
Drawable imagebakground=new BitmapDrawable(getResources(),Imagebackground);
framelayout.setBackground(imagebakground);

I'm using,,

    android:minSdkVersion="14"
    android:targetSdkVersion="19"

Upvotes: 0

Views: 2951

Answers (3)

M D
M D

Reputation: 47807

Set Bitmap as BackgroundDrawable to your Layout instead of setBackground()

 if (Build.VERSION.SDK_INT >= 16)
  your_layout.setBackground(...);
 else
  your_layout.setBackgroundDrawable(...);

It's becoz setBackground() is available from API Level 16

Upvotes: 2

Gopal Gopi
Gopal Gopi

Reputation: 11131

setBackground() method was added into API level 16. use setBackgroundDrawable() instead....

    Drawable imagebakground = new BitmapDrawable(getResources(),Imagebackground);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        framelayout.setBackground(imagebakground);
    } else {
        frameLayout.setBackgroundDrawable(imagebakground);
    }

Upvotes: 4

Blackbelt
Blackbelt

Reputation: 157447

setBackground() is available from API Level 16, so having minSdkVersion set to 14 does not help. The device where you are testing it, has to be at least that api level

Upvotes: 2

Related Questions