Hello i am trying to set a views height but its throwing a null pointer exception at the second line.
Im actually trying to add a header to a list activity. For that my code is:
View header= (View)getLayoutInflater().inflate(R.layout.customheader, null);
getListView.addHeaderView(header);
header.getLayoutParams().height=(int)55; //This line is throwing a null pointer exception
setListAdapter(adapter);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LayoutParams params=new LayoutParams(-1, 55);
View header= (View)getLayoutInflater().inflate(R.layout.customheader, null);
getListView().addHeaderView(header);
getListView().setCacheColorHint(0);
getListView().setBackgroundResource(R.drawable.patterns);
setListAdapter(new Settingsadapter(this, menu));
header.setLayoutParams(params);
}
Exception:
E/AndroidRuntime(504): java.lang.ClassCastException: android.view.ViewGroup$LayoutParams
You are inflating your view, but not adding it anywhere. To set the height, the view needs to be in the application.
If you are trying to retrive part of your existing layout, you need to do this: