Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android应用程序在访问按钮时崩溃_Android_Android Button - Fatal编程技术网

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中看到它