Android.view.InflateException: Binary XML file line #7: Error inflating class button错误的解决方法

版权声明:本文为博主原创文章,如需转载请注明出处,谢谢。 https://blog.csdn.net/zhouxingxingzxy/article/details/40072251

刚开始接触android开发,今天尝试重现网上一个webview的小例子,码完代码后,运行程序时出现如下错误:java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.webview/com.example.webview.WebViewActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class button

工程中的布局文件mainactivity.xml如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    
    <button
        android:id="@+id/Button01"
        android:layout_width="96dp"
        android:layout_height="64dp"
        android:onClick="onClick"
        android:text="@string/Go" />

        <EditText
        android:id="@+id/EditText01"
        android:layout_width="fill_parent"
        android:layout_height="80dp"
        android:inputType="text"
        android:singleLine="true" />
        
    <WebView
        android:id="@+id/WebView01"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

</LinearLayout>

网上查资料发现,这类错误一般是xml布局文件中的标签或者属性的命名有问题,最后查找发现是自己的button标签名未大写导致的错误将button标签名改正后,程序就可以正常运行了!总结:1.在写xml的相关属性/标签时,要注意拼写的准确性(大小写),一致性(控件名要正确)2.注意代码的格式,标签要匹配

参考文章:http://www.cnblogs.com/pinky878/archive/2012/05/17/2506341.html

其他相关错误:http://stackoverflow.com/questions/14565460/error-opening-supportmapfragment-for-second-time

猜你喜欢

转载自blog.csdn.net/zhouxingxingzxy/article/details/40072251
今日推荐