title: How to avoid null pointer in View.getDrawingCache()?
body: <p>My app has this code snippet</p>
  
  <pre><code>mView.setDrawingCacheEnabled(true);
  mBitmap = Bitmap.createBitmap(mView.getDrawingCache());
  </code></pre>
  
  <p>Where mView is an instance of a custom subclass of FrameLayout. The app has worked well for 6 months now with thousands of users. Recently I got few reports (possibly from same user but I cannot confirm) about a null pointer passed to createBitmap(). I don't know what hardware or android version the user uses.</p>
  
  <p>What can cause getDrawingCache() to return null even though I enabled the cache just before it? Is it related to hardware acceleration in new phones? Is it because of insufficient ram for the bitmap? Anything else? Can it be prevented?</p>
  
  <p>Edit: I found this solution here <a href="http://tinyurl.com/7yranvj" rel="noreferrer">http://tinyurl.com/7yranvj</a> . Is it a reasonable workaround?</p>
  
  <pre><code>mBitmap = Bitmap.createBitmap(mView.getWidth(), mView.getHeight(),
          Bitmap.Config.ARGB_8888);
  final Canvas canvas = new Canvas(mBitMap);
  mView.draw(canvas);
  </code></pre>