android.view.InflateException:二进制XML文件行#1:错误膨胀类linearlayout

Sun*_*ary -3 java layout android android-layout

我使用下面的代码来创建带有复选框的对话框: 在此输入图像描述 创建:

        AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
        LayoutInflater adbInflater = LayoutInflater.from(getContext());
        LinearLayout eulaLayout = (LinearLayout) adbInflater.inflate(R.layout.checkbox, null);
        dontShowAgain = (CheckBox)eulaLayout.findViewById(R.id.skip);
Run Code Online (Sandbox Code Playgroud)

checbox.xml的布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_root" android:orientation="horizontal"
    android:layout_height="fill_parent"
    android:padding="10dp">

    <CheckBox 
        android:text="Do not show again" 
        android:id="@+id/skip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        xmlns:android="http://schemas.android.com/apk/res/android">
    </CheckBox>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

laa*_*lto 15

有一个嵌套的"由...引起"异常会给你更具体的失败原因.

但要注意你的资本化.没有,linearlayout但有LinearLayout.这同样适用于CheckBox.

LinearLayout还需要一个layout_width.