Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference at com.example.pcetsnmiet.Fragments.DashBoardFragment.onCreateView(DashBoardFragment.java:34)
dashboardFragment.xml
<?xml version="1.0" encoding="utf-8"?>
<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"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".Fragments.DashBoardFragment"
android:background="#ECB1B1">
<com.denzcoskun.imageslider.ImageSlider
android:id="@+id/image_slider"
android:layout_width="match_parent"
android:layout_height="200dp"
app:iss_auto_cycle="true"
app:iss_period="1000"
app:iss_delay="0"
android:background="#fff"
/>
DashboardFragment.java
public class DashBoardFragment extends Fragment {
ImageSlider imageSlider;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
imageSlider = (ImageSlider) getView().findViewById(R.id.image_slider); //this is the line error pointing at
final List<SlideModel> remoteimages = new ArrayList<>();
FirebaseDatabase.getInstance().getReference().child("Slider")
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
for(DataSnapshot data:snapshot.getChildren())
{
remoteimages.add(new SlideModel(data.child("url").getValue().toString(),data.child("title").getValue().toString(), ScaleTypes.FIT));
}
imageSlider.setImageList(remoteimages,ScaleTypes.FIT);
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_dash_board, container, false);
}
}