剛開始接觸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