Search code examples
androidkotlinandroid-studio

Problems with Android Studio Tutorial = Adding an Image


I am having difficulties with this portion of the tutorial on developer.Android.com. I am on the chapter about adding in an image to your app.

Adding an Image to an App

During the step, I am using the following code, just as stated in the tutorial.

@Composable
fun GreetingImage(message: String, from: String, modifier: Modifier = Modifier) {
    val image = painterResource(R.drawable.androidparty)
    Image(
        painter = image
    )
}

When doing this, if I hover over the Image keyword I get the following error -

Cannot access '': it is package-private in 'Image' Cannot create an instance of an abstract class

as well as the following if I move the cursor over the painter keyword

Cannot create an instance of an abstract class Named arguments are not allowed for non-Kotlin functions Cannot find a parameter with this name: painter

Can't figure out what I am doing wrong.


Solution

  • set the image contentDescription string or null

    Image(
        painter = image,     
        contentDescription = "" //your string or contentDescription = null
    )