android Lollipop 上的 TableLayout 应用程序崩溃

TableLayout Crashing application on android Lollipop

我在我的 activity 布局之一中使用 TableLayout。但是当我在 Lollipop 上尝试 运行 same activity 时它崩溃了。

它适用于棉花糖和牛轧糖。

当我在删除 TableLayout(仅)后尝试 运行 它时,它在 Lollipop 中也能正常工作。

我尝试删除 activity 上的所有 java 代码,它有同样的问题。

我的崩溃报告

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.sovereignconsult.region.viand, PID: 19434 java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getVisibility()' on a null object reference at android.widget.LinearLayout.forceUniformHeight(LinearLayout.java:1380) at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1368) at android.widget.TableRow.onMeasure(TableRow.java:114) at android.view.View.measure(View.java:17826) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5653) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436) at android.widget.TableLayout.measureChildBeforeLayout(TableLayout.java:464) at android.widget.LinearLayout.measureVertical(LinearLayout.java:722) at android.widget.TableLayout.measureVertical(TableLayout.java:476) at android.widget.TableLayout.onMeasure(TableLayout.java:439) at android.view.View.measure(View.java:17826) at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:728) at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:464) at android.view.View.measure(View.java:17826) at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1269) at android.widget.FrameLayout.onMeasure(FrameLayout.java:430) at android.widget.ScrollView.onMeasure(ScrollView.java:338) at android.view.View.measure(View.java:17826) at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:728) at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:464) at android.view.View.measure(View.java:17826) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5653) at android.widget.FrameLayout.onMeasure(FrameLayout.java:430) at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139) at android.view.View.measure(View.java:17826) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5653) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436) at android.widget.LinearLayout.measureVertical(LinearLayout.java:722) at android.widget.LinearLayout.onMeasure(LinearLayout.java:613) at android.view.View.measure(View.java:17826) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5653) at android.widget.FrameLayout.onMeasure(FrameLayout.java:430) at android.view.View.measure(View.java:17826) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5653) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436) at android.widget.LinearLayout.measureVertical(LinearLayout.java:722) at android.widget.LinearLayout.onMeasure(LinearLayout.java:613) at android.view.View.measure(View.java:17826) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5653) at android.widget.FrameLayout.onMeasure(FrameLayout.java:430) at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2748) at android.view.View.measure(View.java:17826) at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2030) at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1174) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1395) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1062) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5873) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767) at android.view.Choreographer.doCallbacks(Choreographer.java:580) at android.view.Choreographer.doFrame(Choreographer.java:550) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5536) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1397) at com.android.internal.

布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/tools"
    xmlns:design="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<include android:id="@+id/toolbar"
    layout="@layout/top_bar"/>
<ScrollView
    android:id="@+id/productscrollview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:ignore="UselessParent"
    android:layout_below="@id/toolbar">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp">

        <TextView
            android:id="@+id/offeringNmae"
            android:textStyle="normal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="20dp"
            android:layout_marginBottom="20dp"
            android:textSize="23sp"
            android:textColor="@color/lildark"
            android:text="Name of Offering" />
        <TextView
            android:id="@+id/terms"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/orderTerms"
            android:layout_below="@id/offeringNmae"
            android:textSize="10sp"
            android:layout_marginBottom="5dp"/>



        <TableLayout
            android:id="@+id/orderDetails"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:stretchColumns="1"
            android:background="@drawable/cell_shape"
            android:layout_below="@id/terms"
            android:layout_marginBottom="10dp">
            <TableRow
                android:paddingTop="10dp"
                android:paddingBottom="10dp">
                <TextView
                    android:layout_column="1"
                    android:text="Details"
                    android:layout_marginStart="15dp"
                    android:textStyle="bold"/>
            </TableRow>
            <View
                android:layout_height="1dp"
                android:background="@color/lightGray"/>
            <TableRow
                android:paddingTop="10dp"
                android:paddingBottom="10dp">
                <TextView
                    android:id="@+id/orderName"
                    android:layout_column="1"
                    android:padding="3dip"
                    android:layout_marginStart="15dp"/>
                <TextView
                    android:id="@+id/quantity"
                    android:layout_column="2"
                    android:gravity="end"
                    android:padding="3dip"/>
                <TextView
                    android:id="@+id/price"
                    android:layout_column="3"
                    android:gravity="end"
                    android:padding="3dip"
                    android:layout_marginEnd="15dp"/>
            </TableRow>

            <View
                android:layout_height="1dp"
                android:background="@color/lightGray"/>
            <TableRow
                android:paddingTop="10dp"
                android:paddingBottom="10dp">
                <TextView
                    android:layout_column="1"
                    android:padding="3dip"
                    android:text="Total Amount"
                    android:layout_marginStart="15dp"/>
                <TextView
                    android:layout_column="3"
                    android:id="@+id/totalamount"
                    android:gravity="right"
                    android:padding="3dip"
                    android:layout_marginEnd="15dp"/>
            </TableRow>

        </TableLayout>
        <TableLayout
            android:id="@+id/orderAddress"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:stretchColumns="1"
            android:background="@drawable/cell_shape"
            android:layout_below="@id/orderDetails"
            android:layout_marginBottom="10dp">
            <TableRow
                android:paddingTop="10dp"
                android:paddingBottom="10dp">
                <TextView
                    android:layout_column="1"
                    android:padding="3dip"
                    android:text="Pickup Address"
                    android:layout_marginStart="15dp"
                    android:textStyle="bold"/>

            </TableRow>
            <View
                android:layout_height="1dp"
                android:background="@color/lightGray"/>
            <TableRow
                android:paddingTop="10dp"
                android:paddingBottom="10dp">

                <TextView
                    android:layout_column="1"
                    android:id="@+id/address"
                    android:layout_height="fill_parent"
                    android:layout_width="wrap_content"
                    android:layout_marginLeft="15dp"
                    android:layout_marginRight="15dp"/>
            </TableRow>
        </TableLayout>
        <TableLayout
            android:id="@+id/chefNote"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:stretchColumns="1"
            android:background="@drawable/cell_shape"
            android:layout_below="@id/orderAddress">
            <TableRow
                android:paddingTop="10dp"
                android:paddingBottom="10dp">
                <TextView
                    android:layout_column="1"
                    android:padding="3dip"
                    android:text="Note For Chef"
                    android:layout_marginStart="15dp"
                    android:textStyle="bold"/>

            </TableRow>
            <View
                android:layout_height="1dp"
                android:background="@color/lightGray"/>
            <TableRow
                android:paddingTop="10dp"
                android:paddingBottom="10dp">

                <TextView
                    android:layout_column="1"
                    android:id="@+id/ChefNote"
                    android:layout_height="fill_parent"
                    android:layout_width="wrap_content"
                    android:layout_marginLeft="15dp"
                    android:layout_marginRight="15dp"/>
            </TableRow>
        </TableLayout>


    </RelativeLayout>
</ScrollView>
<android.support.design.widget.BottomNavigationView
    android:id="@+id/bottom_navigation"
    android:layout_height="60dp"
    android:layout_width="match_parent"
    android:layout_alignParentBottom="true"
    app:itemBackground="@color/defaultText"
    android:background="@color/defaultText"
    android:paddingRight="10dp"
    android:paddingLeft="10dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:gravity="center_horizontal"
        android:weightSum="2">

        <Button
            android:id="@+id/bookbottom"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="@string/PayNow"
            android:layout_weight="1"
            android:background="@drawable/buttonstyledefaultcolor"
            android:layout_gravity="center"
            android:textColor="@color/colorPrimary"
            android:padding="0dp"
            android:layout_marginTop="2dp"/>
    </LinearLayout>


</android.support.design.widget.BottomNavigationView>

public class order_verification_activity extends AppCompatActivity {
    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_verification);
    }
}

既然你说你删除了所有 java 代码,那么我会提出一些建议(将其写在答案中以使其适合)。 你的代码中有一个 <View> inside a <TableLayout> 我怀疑这是错误的尝试调整你的代码以满足这个(你在更多地方有相同的东西请全部改变):

<TableLayout
                android:id="@+id/orderDetails"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:stretchColumns="1"
                android:background="@drawable/cell_shape"
                android:layout_below="@id/terms"
                android:layout_marginBottom="10dp">
                <TableRow
                    android:paddingTop="10dp"
                    android:paddingBottom="10dp">
                    <TextView
                        android:layout_column="1"
                        android:text="Details"
                        android:layout_marginStart="15dp"
                        android:textStyle="bold"/>
                </TableRow>
                <View
                    android:layout_height="1dp"
                    android:background="@color/lightGray"/>
                <TableRow
                    android:paddingTop="10dp"
                    android:paddingBottom="10dp">
                    <TextView
                        android:id="@+id/orderName"
                        android:layout_column="1"
                        android:padding="3dip"
                        android:layout_marginStart="15dp"/>
                    <TextView
                        android:id="@+id/quantity"
                        android:layout_column="2"
                        android:gravity="end"
                        android:padding="3dip"/>
                    <TextView
                        android:id="@+id/price"
                        android:layout_column="3"
                        android:gravity="end"
                        android:padding="3dip"
                        android:layout_marginEnd="15dp"/>
                </TableRow>
                <TableRow
                    android:paddingTop="10dp"
                    android:paddingBottom="10dp">
                    <TextView
                        android:layout_column="1"
                        android:padding="3dip"
                        android:text="Total Amount"
                        android:layout_marginStart="15dp"/>
                    <TextView
                        android:layout_column="3"
                        android:id="@+id/totalamount"
                        android:gravity="right"
                        android:padding="3dip"
                        android:layout_marginEnd="15dp"/>
                </TableRow>

            </TableLayout>
            <TableLayout
                android:id="@+id/orderAddress"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:stretchColumns="1"
                android:background="@drawable/cell_shape"
                android:layout_below="@id/orderDetails"
                android:layout_marginBottom="10dp">
                <TableRow
                    android:paddingTop="10dp"
                    android:paddingBottom="10dp">
                    <TextView
                        android:layout_column="1"
                        android:text="Pickup Address"
                        android:layout_marginStart="15dp"
                        android:textStyle="bold"/>
                </TableRow>
                <View
                    android:layout_height="1dp"
                    android:background="@color/lightGray"/>
                <TableRow
                    android:paddingTop="10dp"
                    android:paddingBottom="10dp">
                    <TextView
                        android:id="@+id/address"
                        android:layout_column="1"
                        android:padding="3dip"
                        android:layout_marginStart="15dp"/>
                </TableRow>
            </TableLayout>
            <TableLayout
                android:id="@+id/noteForCheifa"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:stretchColumns="1"
                android:background="@drawable/cell_shape"
                android:layout_below="@id/orderAddress"
                android:layout_marginBottom="10dp">
                <TableRow
                    android:paddingTop="10dp"
                    android:paddingBottom="10dp">
                    <TextView
                        android:layout_column="1"
                        android:text="Note For Chef"
                        android:layout_marginStart="15dp"
                        android:textStyle="bold"/>
                </TableRow>
                <View
                    android:layout_height="1dp"
                    android:background="@color/lightGray"/>
                <TableRow
                    android:paddingTop="10dp"
                    android:paddingBottom="10dp">
                    <TextView
                        android:id="@+id/ChefNote"
                        android:layout_column="1"
                        android:padding="3dip"
                        android:layout_marginStart="15dp"/>
                </TableRow>
            </TableLayout>



            <TableLayout
                android:id="@+id/paymentmode"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:stretchColumns="1"
                android:background="@drawable/cell_shape"
                android:layout_below="@id/noteForCheifa"
                android:layout_marginBottom="90dp">
                <TableRow
                    android:paddingTop="10dp"
                    android:paddingBottom="10dp">
                    <TextView
                        android:layout_column="1"
                        android:text="Select Payment Method"
                        android:layout_marginStart="15dp"
                        android:textStyle="bold"/>
                </TableRow>
                <View
                    android:layout_height="1dp"
                    android:background="@color/lightGray"/>
                <TableRow
                    android:paddingTop="10dp"
                    android:paddingBottom="10dp">
                    <RadioGroup
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:id="@+id/RGroup">
                        <RadioButton
                            android:id="@+id/SelectTezUpi"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="@string/Tez"
                            android:buttonTint="@color/colorPrimary"/>
                        <RadioButton
                            android:id="@+id/paytm"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="Paytm"
                            android:buttonTint="@color/colorPrimary"/>
                    </RadioGroup>

                </TableRow>
            </TableLayout>

删除 layout_width 和 layout_height 或在 table 行

内的文本视图中制作 layout_height="wrap_content"
 <TableRow
            android:paddingTop="10dp"
            android:paddingBottom="10dp">

            <TextView
                android:layout_column="1"
                android:id="@+id/address"
                android:layout_height="fill_parent"
                android:layout_width="wrap_content"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp"/>
        </TableRow>