I want to set the layout background programatically, depending on the genre of the song to be played in my application. I tried this:

public class AnswerActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Log.e("TRANSITION", "TRANSITIONED TO ANSWER ACTIVITY");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.play); 
        android.support.v7.app.ActionBar actionBar = getSupportActionBar();
        actionBar.hide();
        LinearLayout root = new LinearLayout(this);//(LinearLayout) findViewById(R.id.ctr1);
        Bundle data = getIntent().getExtras();
        if(data.getString("genre").equals("rock")){
            root.setBackgroundResource(R.drawable.wprock);
        }
        else if(data.getString("genre").equals("pop")){
            root.setBackgroundResource(R.drawable.wppop);
        }
        else if(data.getString("genre").equals("hiphop")){
            root.setBackgroundResource(R.drawable.wphiphop);
        }

    }

But it doesn't work, it's throwing a Null Pointer Exception in the root.setBackgroundResource lines, whenever anyone of these take place. Any ideas? Thanks in advance EDIT: I do have R.drawable.wprock/pop/hiphop, plus I ruled out that possiblity bevause I tried to use a color instead with the setBackgroundColor mehtod and I had the same exception.

Related posts

Recent Viewed