package com.example.musicapp.Interface import androidx.compose.foundation.layout.Column…
- User
package com.example.musicapp.Interface
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.material.MaterialTheme import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import androidx.lifecycle.viewmodel.compose.viewModel import com.example.musicapp.Data.Song import com.example.musicapp.ViewModel.AlbumDetailsViewModel
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.items import androidx.compose.material.Text import androidx.compose.ui.unit.dp @Composable fun AlbumDetailScreen(albumId: Int) { val albumDetailsViewModel: AlbumDetailsViewModel = viewModel() albumDetailsViewModel.fetchAlbumDetails(albumId) val albumDetails by albumDetailsViewModel.albumDetails.collectAsState()
codealbumDetails?.let { details -> Column { Text( text = details.title, style = MaterialTheme.typography.h6, modifier = Modifier.padding(start = 16.dp, end = 16.dp, top = 16.dp, bottom = 8.dp) ) LazyColumn { items(details.songs) { song -> SongItem(song) } } } }}
@Composable fun SongItem(song: Song) { Row( modifier = Modifier.padding(8.dp) ) { Text(song.title, modifier = Modifier.padding(end = 8.dp)) Text("Duration: ${song.duration} seconds") } },package com.example.musicapp.Interface
import TopBar import android.util.Log import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.border import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.MaterialTheme import androidx.compose.material.Scaffold import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.unit.dp import androidx.lifecycle.viewmodel.compose.viewModel import androidx.navigation.NavController import coil.compose.rememberAsyncImagePainter import com.example.musicapp.Data.Album import com.example.musicapp.ViewModel.ArtistsViewModel /* @Composable fun ArtistDetailScreen(artistId: Int) { val artistsViewModel: ArtistsViewModel = viewModel() artistsViewModel.fetchArtistDetails(artistId) val artistDetails by artistsViewModel.artistDetails.collectAsState()
- Assistant
@Composable fun AlbumDetailScreen(albumId: Int, navController: NavController) { val albumDetailsViewModel: AlbumDetailsViewModel = viewModel() albumDetailsViewModel.fetchAlbumDetails(albumId) val albumDetails by albumDetailsViewModel.albumDetails.collectAsState()
- User
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.musicapp, PID: 7407 java.lang.IllegalArgumentException: Navigation destination that matches request NavDeepLinkRequest{ uri=android-app://androidx.navigation/songDetail/{song.id} } cannot be found in the navigation graph NavGraph(0x0) startDestination={Destination(0x245ddaf4) route=musicCategories} at androidx.navigation.NavController.navigate(NavController.kt:1664) at androidx.navigation.NavController.navigate(NavController.kt:1984) at androidx.navigation.NavController.navigateAlbumDetailItemAlbumDetailItemclickablegesture1clickablegesture1detectTapAndPress1.invokeSuspend(TapGestureDetector.kt:255) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTaskKt.resume(DispatchedTask.kt:178) at kotlinx.coroutines.DispatchedTaskKt.dispatch(DispatchedTask.kt:166) at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.kt:397) at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl(CancellableContinuationImpl.kt:431) at kotlinx.coroutines.CancellableContinuationImpl.resumeImplPointerEventHandlerCoroutine.offerPointerEvent(SuspendingPointerInputFilter.kt:566) at androidx.compose.ui.input.pointer.SuspendingPointerInputFilter.dispatchPointerEvent(SuspendingPointerInputFilter.kt:456) at androidx.compose.ui.input.pointer.SuspendingPointerInputFilter.onPointerEvent-H0pRuoY(SuspendingPointerInputFilter.kt:469) at androidx.compose.ui.node.BackwardsCompatNode.onPointerEvent-H0pRuoY(BackwardsCompatNode.kt:374) at androidx.compose.ui.input.pointer.Node.dispatchMainEventPass(HitPathTracker.kt:314) at androidx.compose.ui.input.pointer.Node.dispatchMainEventPass(HitPathTracker.kt:301) -> this is the error when i clicked to an album detail item
- Assistant
You got a crash when you clicked on an AlbumDetailItem because there is no navigation destination set up for the "songDetail/{song.id}" route in your navigation graph.
First, create a new Composable for Song Detail Screen, for example:
kotlin@Composable fun SongDetailScreen(songId: Int) { // Display song details here. }Then you need to set up a new navigation destination in your navigation graph like this:
kotlin