android.widget.Button cannot be cast to android.widget.EditText

前端 未结 4 873
轮回少年
轮回少年 2021-01-12 09:36

Developing my first Android calculator application, I succeeded in updating a TextView in a new activity by passing the answer via an intent, but this requires the user to h

相关标签:
4条回答
  • 2021-01-12 10:18

    i was having the same situation but i found out that there are two textviews with same ids in different activities so i changed one of them and the program ran clearly so check the ids of all your edittext and buttons and change the samilier even if they were in other activities and i think it will run with out any problems

    0 讨论(0)
  • 2021-01-12 10:19

    I followed the steps in the answer (cleaned and then made sure it's the id) and noticed that going to the source of my EditText R.id brings me to the EditText. Thought this is definitely not a IDE cache problem.

    What I did do is to change the LinearLayout

    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    

    to

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    

    For some reason it fixed the issue (I had this whole layout wrapped in something else that I just recently removed).

    0 讨论(0)
  • 2021-01-12 10:22

    It seems like either R.id.number1 or R.id.number2 is a Button. Check your XML and make sure it's an EditText.

    Edit: Original answer didn't work, but cleaning the project solved the problem.

    0 讨论(0)
  • 2021-01-12 10:36

    I've just had this problem. It seems that the xml layout file is not compiled properly. Or rather it is not included in the list of changed files to be compiled.

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