0

I want to change the Background of a FrameLayout. This is the code I use right now:

FrameLayout.setBackground(getResources().getDrawable(R.drawable.background));

But this error occurs:

Non-static method 'setBackground(android.graphics.drawable.Drawable)' cannot be referenced from a static context.

What is wrong there?

2Dee
  • 8,609
  • 7
  • 42
  • 53
M P
  • 113
  • 1
  • 4
  • 15
  • possible duplicate of ["Non-static method cannot be referenced from a static context" error](http://stackoverflow.com/questions/4922145/non-static-method-cannot-be-referenced-from-a-static-context-error) – user207421 Oct 21 '14 at 09:21

1 Answers1

0

FrameLayout is a class. When you call FrameLayout.setBackground() you are attempting to call a static method called setBackground() on the FrameLayout class itself. This error is telling you that such a static method does not exist.

What you really want to do is call the setBackground() method on a particular instance of a FrameLayout.

First you need to obtain a reference to your FrameLayout (generally through a call to findViewById(), then call setBackground() on that.

Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120