I have some injections in viewModels (like room) without problem Now i'm trying to inject into my fragment but the app crash.
Fragment:
@AndroidEntryPoint
class ContactListFragment @Inject constructor(private val newContactDialog: NewContactDialog) :
Fragment() {
}
Module:
@Module
@InstallIn(SingletonComponent::class)
object ContactModule {
@Provides
@Singleton
fun provideNewContactDialog(): NewContactDialog {
return NewContactDialog()
}
@Provides
@Singleton
fun provideContactListFragment(contactDialog: NewContactDialog): ContactListFragment {
return ContactListFragment(contactDialog)
}
}
part of the error
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.roomcontactlist/com.example.roomcontactlist.MainActivity}: android.view.InflateException: Binary XML file line #18 in com.example.roomcontactlist:layout/activity_main: Binary XML file line #18 in com.example.roomcontactlist:layout/activity_main: Error inflating class androidx.fragment.app.FragmentContainerView
and the main activity xml
<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"
tools:context=".MainActivity">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragmentContainerView"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/main_navgraph" />
</androidx.constraintlayout.widget.ConstraintLayout>
line 18 is app:navGraph="@navigation/main_navgraph"