Marcin Bortel
Marcin Bortel

Reputation: 1259

Trying to instantiate a class androidx.navigation.fragment.NavHostFragment that is not a Fragment

as in the title:

Trying to instantiate a class androidx.navigation.fragment.NavHostFragment that is not a Fragment

I've got a two activities. Both have following code with different ids and reference to different navigation graphs

<fragment
        android:id="@+id/splash_nav_host_fragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:defaultNavHost="true"
        app:navGraph="@navigation/navigation_splash"/>

When i comment above code application runs ok. In First activity i can navigate to second activity and app works just fine. When i uncomment above code - app crashes

Any help?

Upvotes: 10

Views: 3049

Answers (1)

Marcin Bortel
Marcin Bortel

Reputation: 1259

I was extending Activity but i should AppCompatActivity.

Now everything works fine.

Upvotes: 29

Related Questions