I was trying to change the height of a fragment programmatically.
I could get the result in XML having the fragment layout height to 650dp;
But I want to change that dynamically.
Inside the onCreateView of fragment I wrote the below code which throws a NullPointerException -
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_group_info, container, false);
try {
ViewGroup.LayoutParams params = v.getLayoutParams();
params.height = 610;
v.setLayoutParams(params);
} catch (Exception e) {
Log.d("ListView1", "GroupInfoFragment Height Exception: " + e.toString());
}
mListView = (ListView) v.findViewById(android.R.id.list);
rv =v;
return v;
}
the Exception -
GroupInfo Fragment Height Exception: java.lang.NullPointerException:
Attempt to invoke virtual method 'android.view.View android.app.Fragment.getView()'
on a null object reference