Reputation: 73
I am running the project where i got the error that no suitable parent found from the given view. Logcat error Caused by: java.lang.IllegalArgumentException: No suitable parent found from the given view. Please provide a valid view. at com.google.android.material.snackbar.Snackbar.make(Snackbar.java:158) at com.example.uberclone.ui.home.HomeFragment.init(HomeFragment.java:133) at com.example.uberclone.ui.home.HomeFragment.onCreateView(HomeFragment.java:119)
this is my code
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
homeViewModel = new ViewModelProvider(this).get(HomeViewModel.class);
View root = inflater.inflate(R.layout.fragment_home, container, false);
init();
mapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
return root;
}
private void init() {
onlineRef = FirebaseDatabase.getInstance().getReference().child(".info/connected");
if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
Snackbar.make(getView(), getString(R.string.permission_require), Snackbar.LENGTH_SHORT).show();
return;
}
Upvotes: 0
Views: 2179
Reputation: 54
Snackbar.make(getActivity().findViewById(android.R.id.content), getString(R.string.permission_require), Snackbar.LENGTH_SHORT).show();
you are not providing parent view to the snackbar try using this code.
Upvotes: 2