kotlinandroid-studioandroid-jetpack-compose

What is causing the error `Cannot access '<init>': it is package-private in 'Icon'`?


It's occurring in the following code:

Scaffold(
    floatingActionButton = {
        FloatingActionButton(onClick = {}) {
            Icon(Icons.Default.Add, contentDescription = "Add")
        }
    },
    bottomBar = {
        BottomAppBar(
            actions = {
                IconButton(onClick = {}) {
                    Icon(Icons.Filled.Edit)
                }
            }
        )
    }
)

In IconButton, Icon is underlined with the following error: Cannot access '<init>': it is package-private in 'Icon' and Icons.Filled.Edit is underlined with the following error: Too many arguments for public/*package*/ constructor Icon() defined in android.graphics.drawable.Icon. The icon in the FloatingActionButton is not throwing an error.

For the icon, I have the imports:

import androidx.compose.material3.Icon
import androidx.compose.material.icons.Icons

Solution

  • You need to add contentDescription parameter:

    ...
    Icon(Icons.Default.Edit, contentDescription = "Edit")
    ...
    

    it is a mandatory parameter.