java.lang.NullPointerException: You cannot start a load on a not yet attached View or a Fragment where getActivity() returns null (which usually occurs when getActivity() is called before the Fragment is attached or after the Fragment is destroyed).
在自定义view构造函数中初始化变量,结果NullPointerException
本以为自定义view构造函数是层次调用的
自定义view在使用时,只调用某一个构造方法
public Banner(Context context) {
super(context);
Log.d("my","constructor1");
}
public Banner(Context context, AttributeSet attrs) {
super(context, attrs);
Log.d("my","constructor2");
}
public Banner(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
Log.d("my","constructor3");
}
public Banner(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
this.conte