我是一个新的安卓开发者,我在应用程序中使用了一个ImageButton
,并在后台添加了一些图像。一切在层中看起来都不错,但是当我想在某个类中使用它并使用下面的代码时,它将强制关闭。
Help_Button = (Button) findViewById(R.id.Help_Button);
发布您的布局 xml 会有很大帮助,但我敢打赌,您在尝试将ImageButton
投射到Button
时会得到一个ClassCastException
。试试这个。
ImageButton helpButton = (ImageButton) findViewById(R.id.Help_Button);
Button
和ImageButton
是彼此不同的。 你必须使用ImageButton
而不是Button
。