In my app I need to know what is the size of main container of activity. I have written following code:
Button btnActionMenu = (Button) findViewById(R.id.actionbar_menu);
btnActionMenu.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
int width = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40, getResources().getDisplayMetrics());
RelativeLayout rlContainer = (RelativeLayout) findViewById(R.id.inner_content);
Bitmap bitmap = Bitmap.createBitmap(rlContainer.getLayoutParams().width, rlContainer.getLayoutParams().height, Config.ARGB_8888);//
Canvas canvas = new Canvas(bitmap);
rlContainer.draw(canvas);
SlideoutHelper.setBitmap(bitmap, width);
startActivity(new Intent(Home.this, MenuActivity.class));
overridePendingTransition(0, 0);
}
});
rlContainer
is the root container of activity. When I run and click on button, the application crashes and Logcat says "Application Null pointer exception" and points to line
Bitmap bitmap = Bitmap.createBitmap(rlContainer.getLayoutParams().width, rlContainer.getLayoutParams().height, Config.ARGB_8888);
any suggestion would be appreciated. Thanks