gpt4 book ai didi

android - Android Lollipop 上的 TableLayout 应用程序崩溃

转载 作者:行者123 更新时间:2023-12-02 17:52:19 26 4
gpt4 key购买 nike

我在我的 Activity 布局之一中使用 TableLayout。但是当我尝试在 Lollipop 上运行相同的 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);
}
}

最佳答案

在表格行内的textview中删除layout_width和layout_height或使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>

关于android - Android Lollipop 上的 TableLayout 应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47589895/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com