Android View膨胀异常(空点)

时间:2018-10-22 13:43:18

标签: android xml android-layout view nullpointerexception

我有列表项行,直到我添加 view 作为边框得到NullPointerException时,它才能正常工作。我不明白如果我发表看法,一切都会好起来的。

    <android.support.v7.widget.CardView
        android:id="@+id/cardView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/custom_bg"
        android:focusable="true"
        card_view:cardElevation="4dp"


        card_view:cardUseCompatPadding="true">

        <LinearLayout
            android:layout_width="match_parent"

            android:layout_height="match_parent"
            android:background="@drawable/custom_bg"
            android:orientation="vertical">


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">


                <TextView
                    android:id="@+id/tvUpazilas"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="5dp"
                    android:text="Upazila Name :"
                    android:textColor="#73A7D5"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/tvUpazilaName"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="5dp"
                    android:text="Upazila Name"
                    android:textColor="#2F3133" />


            </LinearLayout>

            <view
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="#dbe3f1" />

           </LinearLayout>
    </android.support.v7.widget.CardView>


</LinearLayout>

logcat

     com.primetech.gis E/UncaughtException: android.view.InflateException: Binary XML file line #67: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:768)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734)

1 个答案:

答案 0 :(得分:2)

请替换掉

 <view
     android:layout_width="match_parent"
     android:layout_height="1dp"
     android:background="#dbe3f1" />

与此

 <View
     android:layout_width="match_parent"
     android:layout_height="1dp"
     android:background="#dbe3f1" />