0

I am trying to open a fragment from a Bottom Sheet, however when I run the app and click the button in the Bottom Sheet that is supposed to do this, the app crashes.

The Build failure that shows up is:

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0. Use '--warning-mode all' to show the individual deprecation warnings.

How can I open a fragment from my Bottom Sheet. Thank you in advance!

import android.os.Bundle;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;

public class BottomSheet extends BottomSheetDialogFragment  {
Button flood
FragmentManager fragmentManager;
FragmentTransaction fragmentTransaction;


public BottomSheet() {

}

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
}

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.bottom_sheet, container, false);
    flood = v.findViewById(R.id.flood);
   


    flood.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            EmergencyContacts nextFrag= new EmergencyContacts();
            getActivity().getSupportFragmentManager().beginTransaction()
                    .replace(R.id.fragment_container, nextFrag, "findFragment")
                    .addToBackStack(null)
                    .commit();
        }
    });
    return v;
} }

Gradle Dependencies:

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-firestore:17.1.2'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.android.material:material:1.3.0-alpha02'


testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Tanay N
  • 17
  • 8
  • Unless you use the support library, FragmentTransaction and FragmentManager are deprecated, but your app should still compile. Can you share your gradle and your imports? – Will Aug 18 '20 at 22:31
  • share your `gradle dependencies` and imports in this class `BottomSheet ` – Mohammad Imran Aug 18 '20 at 22:54
  • @MohammadImran and Will, thank you for the help! I made the edits you guys recommended – Tanay N Aug 18 '20 at 23:42
  • It compiles on my end so I would suggest this: https://stackoverflow.com/questions/54192538/deprecated-gradle-features-making-it-incompatible-with-gradle-5-0-android-studi to see what causes this. It might come from another class. On a side note, if you're using Android Studio, try to review the warnings: you're missing a semi-colon after declaring `Button flood`, `getActivity().getSupportFragmentManager()` may throw `NullPointerException` so add `requireActivity()`, half your imports aren't needed, etc... – Will Aug 19 '20 at 00:40
  • @Will I realized that there was a problem with my Logcat, and I fixed that. So, now I can see the error that comes up when the app crashes. Using that, I was able to solve my problem. Thank you so much for taking the time to help out! – Tanay N Aug 19 '20 at 01:32

0 Answers0