Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 713
Marcin Bortel Avatar asked May 28 '19 23:05

Marcin Bortel


1 Answers

I was extending Activity but i should AppCompatActivity.

Now everything works fine.

like image 191
Marcin Bortel Avatar answered Oct 19 '22 16:10

Marcin Bortel