I am trying to make the tutorials from a Jetpack Compose book but the app crashes when I start it:
This is the error code
2022-09-15 22:03:05.983 14360-14360/com.raywenderlich.android.jetreddit E/AndroidRuntime: FATAL EXCEPTION: main Process: com.raywenderlich.android.jetreddit, PID: 14360 java.lang.IllegalArgumentException: Only VectorDrawables and rasterized asset types are supported ex. PNG, JPG at androidx.compose.ui.res.PainterResources_androidKt.loadImageBitmapResource(PainterResources.android.kt:99) at androidx.compose.ui.res.PainterResources_androidKt.painterResource(PainterResources.android.kt:71) at com.raywenderlich.android.jetreddit.components.PostKt.ImageContent(Post.kt:196) at com.raywenderlich.android.jetreddit.components.PostKt$ImagePost$1.invoke(Post.kt:74) at com.raywenderlich.android.jetreddit.components.PostKt$ImagePost$1.invoke(Post.kt:73) at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107) at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
That's the position from the error code:
@Composable
fun ImageContent(image: Int) {
val imageAsset = ImageBitmap.imageResource(id = image)
Image(
bitmap = imageAsset,
contentDescription = stringResource(id = R.string.post_header_description),
modifier = Modifier
.fillMaxWidth()
.aspectRatio(imageAsset.width.toFloat() / imageAsset.height),
contentScale = ContentScale.Crop
)
}
@Composable
fun ImagePost(post: PostModel) {
Post(post) {
ImageContent(post.image ?: R.drawable.compose_course)
}
}