【发布时间】:2016-07-20 07:29:35
【问题描述】:
我想以编程方式添加一个按钮,也应该设置 LayoutParams。 不幸的是,该应用程序给出了一个例外:
java.lang.NullPointerException:尝试写入字段'int android.view.ViewGroup$LayoutParams.height' 在空对象引用上
我不知道,为什么。你可以帮帮我吗? 这是我的代码。
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;
【问题讨论】:
标签: java android android-layout