I am trying to view a list of item. From mainActiv...
# compose
a
I am trying to view a list of item. From mainActivity class, I am passing arrayList of item to composable function. But while running the app, I am getting this error
java.lang.RuntimeException: Unable to start activity ComponentInfo{<http://package.name/package.name.MainActivity|package.name/package.name.MainActivity>}: java.lang.IllegalStateException: Composition requires an active composition context
My mainActivity class
Copy code
class MainActivity : AppCompatActivity() {
    var dashboardList: ArrayList<Dashboard> = ArrayList()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        fillDummyData()
        setContent {
           MainScreen(dashboardList)
        }
    }
    fun fillDummyData() {
        dashboardList.add(
            Dashboard(title="Sample title",preview="nfjsad dsaf  safsadf ", image= +imageResource(R.drawable.icon), dateTime = "Aug 10", isOnline = "true")
        )
    }
}
If i remove fillDummyData function everything is working fine.
l
You’re calling
Dashboard
which I guess is a
@composable
function outside a composition
Try adding a
model
to the list, and reference the model from a
@Composable
function
a
Dashboard is a data class
Okay I got your point +imageResource is composable function Now making
fillDummyData
function
@Composable
is working
l
Hmmmm
Not sure that’s the best solution though
I’d store the ID in the dataclass
and retrieve the actual image inside a
composition
so from a function which is somewhere `inside`/`nested` in the
setContent
- which is to be considered a starting point for composition
as it interally calls
Compose.composeInto()
a
Okay i will do the same Thanks.
l
Nw .:)