我正在尝试制作一个简单的android项目。它由一个显示另一个 Activity 的按钮组成。你能告诉我这有什么问题
cannot convert from view to button
最后一行有错误吗?
public class Main extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button b = findViewById(R.id.button1);
}
}
最佳答案
你必须将 View 转换到按钮
Button b = (Button) findViewById(R.id.button1);
关于java - 无法从 View 转换为按钮错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32507347/