0

当我启动时,我有这个错误 android.view.ViewRootImpl$CalledFromWrongThreadException: 只有创建视图层次结构的原始线程才能触摸它的视图。

class FirstFragment : Fragment(){
    private val TAG: String = "Information from app"
    lateinit var response:Response<Reqres>
    private lateinit var post :Reqres
    public lateinit var listus :List<databases>
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
        Log.i(TAG, "Info about onCreateView1")
        val view = inflater.inflate(R.layout.fragment_first, container, false)
        val recycle= view.findViewById<RecyclerView>(R.id.recyclerview)
        recycle.layoutManager = LinearLayoutManager(activity)
        GlobalScope.launch(Dispatchers.IO) {

            response = App.getApi().getData().execute()
            post=response.body()
            listus = post.data
            recycle.adapter = Recycleadapter(listus)
        }

        return view
    }
4

0 回答 0