简体   繁体   English

ANDROID-KOTLIN 应用程序在启动前崩溃

[英]ANDROID-KOTLIN App crashing before starting

I am trying to make the tutorials from a Jetpack Compose book but the app crashes when I start it:我正在尝试从 Jetpack Compose 书中制作教程,但是当我启动它时应用程序崩溃了:

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. 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支持光栅化资产类型。 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) 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) 在 androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107) 在 androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda. jvm.kt:34)

That's the position from the error code:那是错误代码中的 position:

@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)
    }
}

From the exception, It seems you are trying to load an image that is not supported by ImageBitmap.imageResource .从异常来看,您似乎正在尝试加载ImageBitmap.imageResource不支持的图像。

java.lang.IllegalArgumentException: Only VectorDrawables and rasterized asset types are supported ex. java.lang.IllegalArgumentException:仅支持 VectorDrawables 和光栅化资产类型,例如。 PNG, JPG. PNG,JPG。

Check that if the type of post.image or R.drawable.compose_course is supported by the API you are using.检查您正在使用的 API 是否支持post.imageR.drawable.compose_course的类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM