[SOLVED] App crashes after clicking on setting before the content is loaded

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under
CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.


My app crashes or goes back to home screen when someone click on settings in exo player twice, pressing it once shows ” Please wait for the content to load ” toast but pressing it twice crashes the app, although after the content is loaded the app doesn’t crash, you can click on it as many times as you want. how do I solve it?

ImageView img_audio = findViewById(R.id.img_audio);
    img_audio.setOnClickListener(view -> {
        if (contentLoaded) {
            MappingTrackSelector.MappedTrackInfo mappedTrackInfo;
            DefaultTrackSelector.Parameters parameters = trackSelector.getParameters();
            TrackSelectionDialog trackSelectionDialog =
                            /* onDismissListener= */ dismissedDialog -> {
            trackSelectionDialog.show(getSupportFragmentManager(), null);
        } else {
            Toast.makeText(DetailsActivity.this, R.string.please_wait, Toast.LENGTH_LONG).show();

        // Active playback.
        contentLoaded = true;

enter image description here


Probably from setting the condition to true, on the first click. Then on the second click, it tries to access the content, which is not loaded. Or why is the content for sure loaded, when the event was fired once?

// Active playback.
contentLoaded = true;

Answered By – ILikeTrains

people found this article helpful. What about you?