报错: Binary XML file line #80 in com.android.deskclock:layout/timer_fragment: null cannot be cast to non-null type android.widget.NumberPicker
场景条件:fragment翻转屏幕重新创建;
xml布局中引入自定义布局view;
自定义view中使用LayoutInflater.from(context).inflate(R.layout.timer_setup_container, this);
timer_setup_container.xml中使用include加载另一个xml(bxml);
bxml视图中同时亦使用include加载xml(cxml);
报错现象:屏幕翻转后app闪退,报错在cxml中findViewById找不到相关viewId;
解决:timer_setup_container.xml布局中取消使用include方式,直接把bxml布局放到timer_setup_container中
注:当然可以在AndroidManifest.xml使用禁止屏幕旋转的方式避免出现该现象:android:screenOrientation="portrait" ,或activity设置android:configChanges="orientation|screenSize,调用onConfigurationChanged不会重新创建