public class home_fragment extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
private AppBarConfiguration mAppBarConfiguration;
private DrawerLayout drawer;
private ImageView profilepic;
private DatabaseReference mDatabaseRef;
private FirebaseAuth mAuth;
private StorageReference storageReference;
FirebaseUser firebaseUser;
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.navi_home:
getSupportFragmentManager().beginTransaction().replace(R.id.nav_host_fragment,new com.example.docsapp.HomeFragment()).commit();
break;
case R.id.navi_favourites:
getSupportFragmentManager().beginTransaction().replace(R.id.nav_host_fragment,new FavouriteFragment()).commit();
break;
case R.id.navi_search:
getSupportFragmentManager().beginTransaction().replace(R.id.nav_host_fragment,new SearchFragment()).commit();
break;
}
return true;
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
mAuth=FirebaseAuth.getInstance();
firebaseUser = mAuth.getCurrentUser();
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
drawer = findViewById(R.id.drawer_layout);
NavigationView navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this,drawer,toolbar,R.string.navigation_drawer_open,R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
try {
BottomNavigationView navigation = findViewById(R.id.nav_view);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
}catch (Exception e){
FancyToast.makeText(getApplicationContext(),e.getMessage(),FancyToast.LENGTH_LONG,FancyToast.ERROR,true).show();
}
if (savedInstanceState==null){
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,new HomeFragment()).commit();
try {
getSupportFragmentManager().beginTransaction().replace(R.id.nav_host_fragment,new com.example.docsapp.HomeFragment()).commit();
}catch (Exception e){
FancyToast.makeText(getApplicationContext(),e.getMessage(),FancyToast.LENGTH_LONG,FancyToast.ERROR,true).show();
}
}
UpdateNavHeader();
}
Ниже приведен код активности_дома
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?android:actionBarSize"
android:background="@color/colorPrimary"
android:id="@+id/toolbar"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:elevation="4dp"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fragment_container"/>
</LinearLayout>
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_home"
app:menu="@menu/drawer_menu" />
</androidx.drawerlayout.widget.DrawerLayout>
Ниже приведен код home_fragment
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/navi_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/windowBackground"
app:menu="@menu/bottom_nav_menu"
android:layout_alignParentBottom="true"/>
<include
android:id="@+id/nav_host_fragment"
layout="@layout/fragment_home"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="8dp" />
</RelativeLayout>
Я пытаюсь открыть фрагмент из фрагмента. Фрагмент imпопытка открытия показывает ошибку. Домашний фрагмент состоит из навигационного ящика и нижней навигации.
Я пытаюсь открыть фрагмент из фрагмента. Фрагмент, который я пытаюсь открыть, показывает ошибку. Домашний фрагмент состоит изнавигационный ящик, а также нижняя навигация.
Ошибка отображается при отображении времени выполнения здесь .