MyLinearLayout.getDrawingCache() gives a NullPointerException
<p>edit:</p>

<p><strong>Nevermind, got it working that way</strong></p>

<pre><code>TopRatedPage.setDrawingCacheEnabled(true);
TopRatedPage.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
TopRatedPage.layout(0, 0, TopRatedPage.getMeasuredWidth(), TopRatedPage.getMeasuredHeight()); 
TopRatedPage.buildDrawingCache(true);
Bitmap screenshot = Bitmap.createBitmap(TopRatedPage.getDrawingCache());
TopRatedPage.setDrawingCacheEnabled(false);
</code></pre>

<hr>

<p>old:</p>

<p>I'm trying to take a screenshot from a layout, like so.</p>

<pre><code>LinearLayout TopRatedPage = (LinearLayout)inflater.inflate(R.layout.toprated, null);
...
Bitmap screenshot;
TopRatedPage.setDrawingCacheEnabled(true);
screenshot = Bitmap.createBitmap(TopRatedPage.getDrawingCache()); // Caused by: java.lang.NullPointerException
TopRatedPage.setDrawingCacheEnabled(false);
</code></pre>

<p>Any ideas what I have done wrong?</p>

<p>Thanks!</p>

<p>edit:
also tried like this, it doesn't throw an error, but given an empty bitmap.</p>

<pre><code>Bitmap screenshot = TopRatedPage.getDrawingCache();
</code></pre>
