2012-04-23 49 views
3

編集を与えますそういうわけで、レイアウトから。MyLinearLayout.getDrawingCacheは、()はNullPointerException

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); 

私が間違って行ったことはありますか?

ありがとうございます!

編集: このようにしても、エラーは発生しませんが、空のビットマップが指定されています。

Bitmap screenshot = TopRatedPage.getDrawingCache(); 

答えて

1

また、使用可能な場合、

LinearLayout TopRatedPage = (LinearLayout)inflater.inflate(R.layout.toprated, null); 
Bitmap screenshot = Bitmap.createBitmap(LinearLayout .getWidth(), LinearLayout .getHeight(), Bitmap.Config.ARGB_8888); 
Canvas c = new Canvas(screenshot); 
LinearLayout.draw(c); 
imageView.setImageBitmap(screenshot); 

View captureView = null; 
captureView = inflater.inflate(R.layout.toprated, null); 
Bitmap screenshot = Bitmap.createBitmap(captureView.getWidth(), captureView.getHeight(), Bitmap.Config.ARGB_8888); 
Canvas c = new Canvas(screenshot); 
captureView .draw(c); 
imageView.setImageBitmap(screenshot); 
+1

感謝の男は、すでにそれはそれらのMeasureSpecで作業してしまった。これを試してみて、私が起こるか知ってみましょう。それがなければ、ビットマップのサイズは0x0でした。 :) –

関連する問題