Getting error while setting BottomSheetBehavior in bottom sheet
Main Linear layout of bottom sheet :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="444dp"
android:background="#F0F0F1"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:orientation="vertical"
android:padding="10dp"
app:behavior_hideable="true"
app:behavior_peekHeight="120dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
Code where i set bottom sheet :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
tools:context=".RatingsActivity">
<include
android:id="@+id/contentMain"
layout="@layout/content_main" />
<include
android:id="@+id/bottomSheet"
layout="@layout/bottom_sheet" />
</RelativeLayout>
This is how i set the bottomsheet behavior callback in code :
bottom_sheet = findViewById(R.id.bottom_sheet);
sheetBehavior = BottomSheetBehavior.from(bottom_sheet);
sheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View view, int i) {
if (i == BottomSheetBehavior.STATE_DRAGGING) {
sheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}
}
@Override
public void onSlide(@NonNull View view, float v) {
}
});
But it shows error :
"Attempt to invoke virtual method 'android.view.ViewGroup$LayoutParams android.view.View.getLayoutParams()' on a null object reference"
in :
sheetBehavior = BottomSheetBehavior.from(bottom_sheet);