E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.deezermusicplayer, PID:…
- User
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.deezermusicplayer, PID: 4393 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 androidx.navigation.compose.NavHostKt.NavHost(NavHost.kt:104) at androidx.navigation.compose.NavHostKt.NavHost(NavHost.kt:67) at com.example.deezermusicplayer.MainActivity.NavigationHost(MainActivity.kt:87) at com.example.deezermusicplayer.MainActivity2.invoke(MainActivity.kt:138) at com.example.deezermusicplayer.MainActivity2.invoke(MainActivity.kt:137) at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:116) -> this is the error i had when i ran the app. import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.compose.foundation.layout.padding import androidx.compose.material.* import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Home import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.lifecycle.ViewModelStore import androidx.navigation.NavController import androidx.navigation.NavHostController import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.currentBackStackEntryAsState import androidx.navigation.compose.rememberNavController import com.example.deezermusicplayer.Category import com.example.deezermusicplayer.Screen import com.example.deezermusicplayer.ui.theme.DeezerMusicPlayerTheme
- Assistant
It seems like the issue is related to setting the
ViewModelStoreafter setting the navigation graph. To fix the issue, you can try setting theViewModelStorebefore setting the navigation graph.Try changing the order inside
NavigationHostfunction like this:kotlin