LinearLayout bottomSheetViewgroup = (LinearLayout) findViewById(R.id.bottomSheet);
bottomSheetBehavior = BottomSheetBehavior.from(bottomSheetViewgroup);
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); //this line在我的活动的onCreate()方法中有以下代码,在执行最后一行时,我将得到下面的NPE异常:
由: java.lang.NullPointerException:尝试在android.support.design.widget.BottomSheetBehavior.setState(BottomSheetBehavior.java:440)上的空对象引用上调用虚拟方法'java.lang.Object java.lang.ref.WeakReference.get()‘引起的
发布于 2018-05-25 06:56:48
public class ExpandedBottomSheetBehavior<V extends View> extends
android.support.design.widget.BottomSheetBehavior<V> {
public ExpandedBottomSheetBehavior(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onLayoutChild(final CoordinatorLayout parent, final V child, final int layoutDirection) {
return super.onLayoutChild(parent, child, layoutDirection);
}
@Override
public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) {
try {
return super.onInterceptTouchEvent(parent, child, event);
} catch (NullPointerException ignored) {
return false;
}
}
}https://stackoverflow.com/questions/35906125
复制相似问题