Cannot convert from View to Button

后端 未结 3 971
一个人的身影
一个人的身影 2021-01-28 06:29

Very frustrating problem I have here. I have this code:

Button b = findViewById(android.R.id.button1);

And I\'m getting this error on it:

3条回答
  •  深忆病人
    2021-01-28 06:57

    You need to cast the view to Button:

    Button b = (Button) findViewById(android.R.id.button1);
    

    More details at http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html

    In addition, as answered by others, the id is wrong.

提交回复
热议问题