I want to add a button programmatically, which LayoutParams should be set too. Unfortunaly the app gives an exception:
java.lang.NullPointerException: Attempt to write to field 'int android.view.ViewGroup$LayoutParams.height' on a null object reference
I have no idea, why. Could you help me? Here is my code.
Button b = new Button(getApplicationContext());
b.setText(R.string.klick);
ViewGroup.LayoutParams params = b.getLayoutParams();
params.height = ViewGroup.LayoutParams.MATCH_PARENT;
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;