android Lollipop 上的 TableLayout 崩溃应用程序

par*_*ish 5 android android-layout android-tablelayout

我在我的活动布局之一中使用 TableLayout。但是当我尝试在 Lollipop 上运行相同的活动时,它崩溃了。

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

当我在删除 TableLayout(ONLY) 后尝试运行它时,它在 Lollipop 中也运行良好。

我尝试删除活动中的所有 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.measureHorizo​​ntal(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.measureChildHorizo​​ntal(RelativeLayout.java:728) at android.widget.RelativeLayout.onMeasure(RelativeLayout.java: 464) 在 android.view.View.measure(View.java:17826) 在 android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1269) 在 android.widget.FrameLayout.onMeasure(FrameLayout.java:430) 在 android.widget.ScrollView.onMeasure(ScrollView.java:338) 在 android.view.View.measure(View.java:17826) 在 android.widget.RelativeLayout.measureChildHorizo​​ntal(RelativeLayout.java:728) 在 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) 在 android.view.View.measure(View.java:17826) 在 android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5653) 在 android.widget.FrameLayout.onMeasure(FrameLayout.java:430) 在 android .view.View.measure(View.java:17826) 在 android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5653) 在 android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436) 在 android.widget.LinearLayout.measureVertical(LinearLayout.java:722) 在 android.widget.LinearLayout.onMeasure(LinearLayout.java:613) 在 android.view.View.measure(View.java:17826) 在 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)在 android.view.View.measure(View.java:17826) 在 android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2030) 在 android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1174) 在 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.Choreocordgrapher$Callback .run(Choreographer.java:767) 在 android.view.Choreographer.doCallbacks(Choreographer.java:580) 在 android.view.Choreographer.doFrame(Choreographer.java:550) 在 android.view.Choreographer$FrameDisplayEventReceiver.run( Choreographer.java:753) 在 android.os.Handler.handleCallback(Handler.java:739) 在 android.os.Handler.dispatchMessage(Handler.java:95) 在 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) 在 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>
Run Code Online (Sandbox Code Playgroud)

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

Yam*_*sif 1

既然你说你删除了所有的java代码,那么我会建议一些东西(将其写在答案中,以便它适合)。你的代码中有<View>一个<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>
Run Code Online (Sandbox Code Playgroud)