Android.widget,textView cannot be cast to android.widget,button

前端 未结 11 612
你的背包
你的背包 2020-12-08 05:01

I keep getting a runtime error when launching my activity and it says android.widget.textview cannot be cast to android.widget.button?

XML:



        
相关标签:
11条回答
  • 2020-12-08 05:26

    you are trying to cast TextView to Button.

    for TextView do this :

    TextView tv = (TextView)findviewById(R.id.your textviewid present in xml layout file);
    

    for Button :

    Button btn1 = (Button)findviewById(R.id.your buttonid present in xml layout file);
    
    0 讨论(0)
  • 2020-12-08 05:27

    Please attach your java code to find out where the problem is occuring. This problem comes when you are trying to convert the textview to button.

    0 讨论(0)
  • 2020-12-08 05:31

    Project -> Clean can help you.

    0 讨论(0)
  • 2020-12-08 05:35
    1. Project > Clean

    Or

    1. change itemes Id's

    it help :D

    0 讨论(0)
  • 2020-12-08 05:37

    I just encountered the same problem. However, i decided to use only "View" without casting. It works perfectly. "setOnClickListener" works the same for our case.

    e.g. View button = v.findViewById(button_id); button.setOnClickListener(...)

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