title: Programmatically create textview background from drawable in Android
body: <p>I have to set the background programmatically on Android TextView</p>
  
  <p>I have using below code. it's not working and also its gave me nullpointerexception error.</p>
  
  <pre><code>best_deals = (TextView) findViewById(R.id.bestdeals);
   best_deals.setBackground(getResources().getDrawable(
                                         R.drawable.headerradius));
  </code></pre>
  
  <p>but I have to put these </p>
  
  <p><code>best_deals.setTextColor(Color.parseColor("#be2351"));</code> means it's working</p>
  
  <p>what's wrong in above code?</p>
  
  <p>This is my <strong>header_redius.xml</strong>:</p>
  
  <pre><code>&lt;shape xmlns:android="http://schemas.android.com/apk/res/android"
      android:shape="rectangle" android:padding="10dp"&gt;
      &lt;solid android:color="#000000"/&gt;
       &lt;corners 
        android:radius="15dp"
       /&gt;
       &lt;gradient
              android:startColor="#434343"
               android:centerColor="#434343"
              android:endColor="#434343"
              android:angle="270" 
              android:type="linear"
              /&gt;
          &lt;padding android:left="10dp"
       android:top="0dp"
       android:right="10dp"
       android:bottom="0dp"/&gt; 
          &lt;stroke
              android:width="2dp"
              android:color="#000000" /&gt;
              &lt;/shape&gt;
  </code></pre>