E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.deezermusicplayer, PID: 622…
- User
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.deezermusicplayer, PID: 622 java.lang.IllegalStateException: ViewModelStore should be set before setGraph call at androidx.navigation.NavController.setViewModelStore(NavController.kt:2169) at androidx.navigation.NavHostController.setViewModelStore(NavHostController.kt:101) at com.example.deezermusicplayer.MainActivity.NavigationHost(MainActivity.kt:95) at com.example.deezermusicplayer.MainActivity1.invoke(MainActivity.kt:117) at com.example.deezermusicplayer.MainActivity1.invoke(MainActivity.kt:116) at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:116) at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34) at androidx.compose.material.ScaffoldKt111.invoke(Scaffold.kt:322) at androidx.compose.material.ScaffoldKt111.invoke(Scaffold.kt:320) -> this is the error and this is the MainActivity- >package com.example.deezermusicplayer
- Assistant
Upon examining your code, I see that you are initializing
BottomNavigationandNavHosttwice: once inHomeScreenand again insetContent. This is causing the issue you're encountering.To fix this, remove the
Scaffoldcontent inHomeScreen. You should only have theScaffoldcontent in thesetContentblock. Here is how yourHomeScreenshould look:kotlin@Composable fun HomeScreen( categories: List<Category>, navController: NavController, modifier: Modifier = Modifier ) { // HomeScreen content goes here (not the Scaffold) }In the
setContentblock, you would have theScaffoldcontent defined once, withNavigationHostas its content: