Я работаю с Фрагментами и Android студией, и мне нужны navegate в фрагментах из Активности. Всегда я получаю одну и ту же ошибку "Нет просмотра для id 0x7f0800a2".
Основная активность
Fragment newFragment = new HomeFragment();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.nav_hotels, newFragment);
transaction.addToBackStack(null);
transaction.commit();
mobile_navigation
<navigation 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/mobile_navigation"
app:startDestination="@+id/nav_home">
<fragment
android:id="@+id/nav_home"
android:name="com.example.freepapp.ui.home.HomeFragment"
android:label="@string/menu_home"
tools:layout="@layout/fragment_home">
</fragment>
<fragment
android:id="@+id/nav_hotels"
android:name="com.example.freepapp.ui.hotels.HotelsFragment"
android:label="@string/menu_hotels"
tools:layout="@layout/activity_liked_quotes" />
Фрагмент Home
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fragment_home"
tools:context=".ui.home.HomeFragment">
<TextView
android:id="@+id/text_home"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:textAlignment="center"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Фрагмент Hotels
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fragment_hotels"
tools:context=".ui.hotels.HotelsFragment">
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>
Ошибка
java .lang.IllegalArgumentException: не найдено представление для id 0x7f0800a2 (com.example.freepapp: id / nav_hotels) для фрагмента HomeFragment {f896362 (40055ce2-7ab7-41dd-be0b-be0edc89f01a) ) id = 0x7f0800a2}