ConstraintLayout cannot be cast to android.widget.TextView

后端 未结 2 1056
庸人自扰
庸人自扰 2021-01-27 13:37

I keep getting a runtime error when I try to launch an activity.

Line where the error happen:

private OnItemClickListener mDeviceClickListener = new OnIt         


        
相关标签:
2条回答
  • 2021-01-27 14:24

    From the documentation:

    View: The view within the AdapterView that was clicked (this will be a view provided by the adapter)

    In your case the View is the root ConstraintLayout. And as the error says you can't cast it to TextView. To get the info you can use:

    String info = v.findViewById(R.id.textView).getText().toString()

    0 讨论(0)
  • 2021-01-27 14:36

    You just got wrong id for your constrain layout and mixed it up with textview that you have make declaration in MainActivity

    0 讨论(0)
提交回复
热议问题