title: How to convert a LinearLayout to image?
body: <p>I tried the following code to convert the <code>LinearLayout</code> to image: </p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      LinearLayout lyt = (LinearLayout) findViewById(R.id.lyt);
      lyt.setDrawingCacheEnabled(true);
      lyt.buildDrawingCache(true);
  
      Bitmap b = Bitmap.createBitmap(lyt.getDrawingCache());
  
      ImageView img = (ImageView) findViewById(R.id.imageView1);
      img.setImageBitmap(b);
  
  }
  </code></pre>
  
  <p>but I got <code>NullPointerException</code> in :</p>
  
  <pre><code>Bitmap b = Bitmap.createBitmap(lyt.getDrawingCache());
  </code></pre>
  
  <p>where the layout XML is :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical" &gt;
  
  
      &lt;LinearLayout
          android:id="@+id/lyt"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical" &gt;
  
          &lt;Button
              android:id="@+id/button1"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Button 1" /&gt;
  
          &lt;Button
              android:id="@+id/button3"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Button 2" /&gt;
  
          &lt;Button
              android:id="@+id/button2"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="Button 3" /&gt;
  
      &lt;/LinearLayout&gt;
  
      &lt;ImageView
          android:id="@+id/imageView1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/ic_launcher" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>