Android应用程序在访问按钮时崩溃
我正在构建一个应用程序,每当我访问一个按钮时Android应用程序在访问按钮时崩溃,android,android-button,Android,Android Button,我正在构建一个应用程序,每当我访问一个按钮时 按钮btn1=(按钮)findViewById(R.id.\U id) 当我将这段代码放入我的项目中时 运行我的项目时,它会使我的应用程序崩溃,但当我//注释这一行,然后运行一切正常时。我不知道有什么问题! 下面是我的xml代码: <WebView android:layout_width="match_parent" android:layout_height="430dp" android:id="@+id/WebF
按钮btn1=(按钮)findViewById(R.id.\U id)代码>
当我将这段代码放入我的项目中时
运行我的项目时,它会使我的应用程序崩溃,但当我//注释这一行,然后运行一切正常时。我不知道有什么问题!
下面是我的xml代码:
<WebView
android:layout_width="match_parent"
android:layout_height="430dp"
android:id="@+id/WebField"
android:layout_above="@+id/btnFB" />
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/btnNYT" />
你必须使用ImageButton。ImageButton与Button不相关,您无法强制转换它
ImageButton buttonNYT = (ImageButton) findViewById(R.id.btnNYT); // this line has
谢谢
Sriram您必须使用ImageButton。ImageButton与Button不相关,您无法强制转换它
ImageButton buttonNYT = (ImageButton) findViewById(R.id.btnNYT); // this line has
谢谢
Sriram使用图像按钮代替按钮例如
ImageButton buttonNYT = (ImageButton) findViewById(R.id.btnNYT);
使用ImageButton代替按钮
ImageButton buttonNYT = (ImageButton) findViewById(R.id.btnNYT);
使用ImageButton
代替按钮
,也请发布异常。您可以在Android日志中看到它使用ImageButton
代替按钮
,也请发布异常。您可以在Android logcat中看到它