我在扩展 LinearLayout 的自定义视图类的构造函数中的super(context)行上有一个 NullPointerException。使用 android 4.1.2 虚拟设备测试未出现此问题。
public class customView extends LinearLayout {
private NavigationBar navigationBar;
private Activity activity;
public customView(Context context) {
super(context);
activity = (Activity) context;
navigationBar = new NavigationBar(context);
LayoutParams Params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
setLayoutParams(Params);
setOrientation(LinearLayout.VERTICAL);
this.addView(navigationBar);
}