简体   繁体   English

为什么项目捕获 object 给我在 Compose 中找不到参考

[英]Why items captured object giving me No reference found in Compose

I've a data class:我有一个数据 class:

data class Feed_Status(val img:Int, val name_id: String)

I've a class:我有一个 class:

class Feed_helper {

    fun Image_getter(): List<() -> Feed_Status> {

        val Images = listOf {
            Feed_Status(R.drawable.image_demo1, "name1")
            Feed_Status(R.drawable.image_demo2, "name2")
            Feed_Status(R.drawable.image_demo3, "name3")
            Feed_Status(R.drawable.image_demo4, "name4")
            Feed_Status(R.drawable.image_demo5, "name5")
            Feed_Status(R.drawable.image_demo6, "name6")
            Feed_Status(R.drawable.image_demo7, "name7")
            Feed_Status(R.drawable.image_demo8, "name8")
            Feed_Status(R.drawable.image_demo9, "name9")
            Feed_Status(R.drawable.image_demo10, "name10")
            Feed_Status(R.drawable.image_demo11, "name11")
            Feed_Status(R.drawable.image_demo12, "name12")
            Feed_Status(R.drawable.image_demo13, "name13")
            Feed_Status(R.drawable.image_demo14, "name14")
            Feed_Status(R.drawable.image_demo15, "name15")
            Feed_Status(R.drawable.image_demo16, "name16")
            Feed_Status(R.drawable.image_demo17, "name17")
            Feed_Status(R.drawable.image_demo18, "name18")
            Feed_Status(R.drawable.image_demo19, "name19")
            Feed_Status(R.drawable.image_demo20, "name20")
            Feed_Status(R.drawable.image_demo21, "name21")
            Feed_Status(R.drawable.image_demo22, "name22")
            Feed_Status(R.drawable.image_demo23, "name23")
            Feed_Status(R.drawable.image_demo24, "name24")
            Feed_Status(R.drawable.image_demo25, "name25")
            Feed_Status(R.drawable.image_demo25, "name26")
        }

        return Images
    }
}

through which I'm calling items() in lazyRow通过它我在lazyRow中调用items()

@Composable
fun feed() {

    LazyColumn(
        reverseLayout = false,
        modifier = Modifier
            .fillMaxSize(),
        userScrollEnabled = true
    ) {
          // Status(es)
         item {
            LazyRow(
                reverseLayout = false,
                modifier = Modifier
                    .fillMaxWidth()
                    .height(100.dp),
                horizontalArrangement = Arrangement.SpaceBetween,
                userScrollEnabled = true
            ) {
                 val statuses = Feed_helper().Image_getter()
                 items(statuses) { status ->
                    Column(
                        verticalArrangement = Arrangement.Center,
                        modifier = Modifier
                                .width(80.dp)

                    ) {


                        Card(
                            shape = CircleShape,
                            modifier = Modifier
                                .padding(8.dp)
                                .size(64.dp)
                        ) {


                            Image(
                                painterResource(id = status.img),
                                contentDescription = status.name_id + "'s status",
                                contentScale = ContentScale.Crop
                            )

                        }

                        Text(
                            text = status.name_id,
                            modifier = Modifier.fillMaxWidth(),
                            textAlign = TextAlign.Center,
                        )

                    }

                }

            }

        }

    }

}

But whenever I'm calling element from statuses through statuses in items() it is giving me Reference Not found!但是每当我通过items()中的statusesstatuses中调用元素时,它都会给我 Reference Not found!

Callers:来电者:

painterResource(id = status.img) in Image() Image()中的painterResource(id = status.img) )

contentDescription = status.name_id + "'s status" in Image() contentDescription = status.name_id + Image()contentDescription = status.name_id + "'s status"

text = status.name_id in Text文本 = Text中的text = status.name_id

All callers are in items(statuses){ status ->所有来电者都在items(statuses){ status ->

I've been trying to solve this for hours.几个小时以来,我一直在努力解决这个问题。 So any help will be very apreciated.因此,我们将不胜感激任何帮助。

If you find any typo please update it or tell me to fix.如果您发现任何拼写错误,请更新它或告诉我修复。

PS: This is my first time here and I have an almost zero experience on android development and Kotlin. I developed terminal apps and worked on ML kinda work in Python, C++, C. So I may need more information in explanation. PS:这是我第一次来这里,我对 android 开发和 Kotlin 的经验几乎为零。我在 Python、C++、C 开发了终端应用程序并从事 ML kinda 工作。所以我可能需要更多信息来解释。 I started learning Android Development a week ago only.我一周前才开始学习 Android 开发。

Edit: You can ask me any more information.编辑:你可以问我更多信息。

Peace和平

Change the return type of Image_getter to List<Feed_status> instead of it having a type of lambda, and change the braces to parenthesis when you declare the list of them.Image_getter的返回类型更改为List<Feed_status>而不是其类型为 lambda,并在声明它们的列表时将大括号更改为圆括号。

class Feed_helper {

    fun Image_getter(): List<Feed_Status> { // change it to this instead of type of lambda `() -> Feed_status`

        val Images = listOf ( // change it to this instead of braces
           ...
        )

        return Images
    }
}

and import并导入

import androidx.compose.foundation.lazy.items

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

相关问题 AS3 MovieClip一直给我提供NULL对象引用 - AS3 MovieClip keeps giving me a NULL object reference 为什么这段代码给我一个IllegalStateException? - Why is this code giving me a IllegalStateException? 搜索的项目在点击时给我错误的结果 - Searched Items giving me wrong results on click android应用程序中的HttpURLConnection给我“找不到源”错误,无法弄清原因 - HttpURLConnection in android app giving me “Source not found” error, can't figure out why 为什么 Navigator in Compose 会出现 Illegal Argument 错误? - Why Navigator in Compose giving Illegal Argument error? Kotlin:捕获到一个封闭在捕获中时要修改的参考对象中 - Kotlin :Wrapped into a reference object to be modified when captured in a closure 为什么这个查询给我一个空的光标? - Why this query is giving me an empty cursor? 不明白为什么AsyncTask给我一个不兼容的类型 - Not understanding why AsyncTask is giving me an incompatible type 为什么[[MainActivity)getActivity())给我一个NullPointerException? - Why is ((MainActivity) getActivity()) giving me a NullPointerException? 为什么解码字节数组给我一个空指针错误 - Why is decodeByteArray giving me a null pointer error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM