当我在我的在线食品订购应用程序中打开食物详细信息时,我的应用程序崩溃了

时间:2018-05-05 04:45:48

标签: android android-layout android-studio

当我在api 19上打开它时我的应用程序崩溃但是在api 25(牛轧糖)上它没有崩溃但是可折叠的布局显示出突然的行为。

以下是调试报告

                                                                             at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                                                                             at com.example.admin.clicknorder.FoodDetail.onCreate(FoodDetail.java:42) 
                                                                             at android.app.Activity.performCreate(Activity.java:5231) 
                                                                             at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
                                                                             at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) 
                                                                             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
                                                                             at android.app.ActivityThread.access$800(ActivityThread.java:135) 
                                                                             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
                                                                             at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                             at android.os.Looper.loop(Looper.java:136) 
                                                                             at android.app.ActivityThread.main(ActivityThread.java:5001) 
                                                                             at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                             at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) 
                                                                             at dalvik.system.NativeStart.main(Native Method) 
                                                                          Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_shopping_cart_black_24dp.xml from drawable resource ID #0x7f020068
                                                                             at android.content.res.Resources.loadDrawable(Resources.java:2096)
                                                                             at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
                                                                             at android.view.View.<init>(View.java:3554)
                                                                             at android.widget.ImageView.<init>(ImageView.java:123)
                                                                             at android.widget.ImageButton.<init>(ImageButton.java:87)
                                                                             at android.support.design.widget.VisibilityAwareImageButton.<init>(VisibilityAwareImageButton.java:36)
                                                                             at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:157)
                                                                             at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:153)
                                                                             at java.lang.reflect.Constructor.constructNative(Native Method) 
                                                                             at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
                                                                             at android.view.LayoutInflater.createView(LayoutInflater.java:594) 
                                                                             at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
                                                                             at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
                                                                             at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
                                                                             at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
                                                                             at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
                                                                             at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292) 
                                                                             at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                                                                             at com.example.admin.clicknorder.FoodDetail.onCreate(FoodDetail.java:42) 
                                                                             at android.app.Activity.performCreate(Activity.java:5231) 
                                                                             at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
                                                                             at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) 
                                                                             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
                                                                             at android.app.ActivityThread.access$800(ActivityThread.java:135) 
                                                                             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
                                                                             at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                             at android.os.Looper.loop(Looper.java:136) 
                                                                             at android.app.ActivityThread.main(ActivityThread.java:5001) 
                                                                             at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                             at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) 
                                                                             at dalvik.system.NativeStart.main(Native Method) 
                                                                          Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag vector
                                                                             at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:933)
                                                                             at android.graphics.drawable.Drawable.createFromXml(Drawable.java:877)
                                                                             at android.content.res.Resources.loadDrawable(Resources.java:2092)
                                                                             at android.content.res.TypedArray.getDrawable(TypedArray.java:602) 
                                                                             at android.view.View.<init>(View.java:3554) 
                                                                             at android.widget.ImageView.<init>(ImageView.java:123) 
                                                                             at android.widget.ImageButton.<init>(ImageButton.java:87) 
                                                                             at android.support.design.widget.VisibilityAwareImageButton.<init>(VisibilityAwareImageButton.java:36) 
                                                                             at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:157) 
                                                                             at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:153) 
                                                                             at java.lang.reflect.Constructor.constructNative(Native Method) 
                                                                             at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
                                                                             at android.view.LayoutInflater.createView(LayoutInflater.java:594) 
                                                                             at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696) 
                                                                             at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
                                                                             at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
                                                                             at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
                                                                             at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
                                                                             at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292) 
                                                                             at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                                                                             at com.example.admin.clicknorder.FoodDetail.onCreate(FoodDetail.java:42) 
                                                                             at android.app.Activity.performCreate(Activity.java:5231) 
                                                                             at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
                                                                             at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) 
                                                                             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
                                                                             at android.app.ActivityThread.access$800(ActivityThread.java:135) 
                                                                             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
                                                                             at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                             at android.os.Looper.loop(Looper.java:136) 
                                                                             at android.app.ActivityThread.main(ActivityThread.java:5001) 
                                                                             at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                             at java.lang.reflect.Method.invoke(Method.java:515) 
                                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) 
                                                                             at dalvik.system.NativeStart.main(Native Method) 

这个fooddetail.java代码,其中调试器显示问题

 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_food_detail);

这是食物细节xml文件

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 tools:context="com.example.admin.clicknorder.FoodDetail">

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:fitsSystemWindows="true">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing"
        android:layout_width="match_parent"
        android:layout_height="350dp"
        android:fitsSystemWindows="true"
        app:layout_scrollFlags="exitUntilCollapsed"
        app:contentScrim="#0d0e0d"
        app:expandedTitleTextAppearance="@android:color/transparent"
       >


    </android.support.design.widget.CollapsingToolbarLayout>
    <ImageView
        android:id="@+id/image_food"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:contentDescription="@null"
        android:scaleType="centerCrop"
        app:layout_collapseMode="parallax"
        />
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:title="Food Name"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:layout_collapseMode="parallax"
        />

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

  <android.support.design.widget.FloatingActionButton
    android:id="@+id/btnCart"
    android:background="@drawable/ic_shopping_cart_black_24dp"

    app:elevation="6dp"
    app:pressedTranslationZ="12dp"
    app:layout_anchor="@id/app_bar_layout"
    app:layout_anchorGravity="bottom|right|end"
    app:useCompatPadding="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

  <android.support.v4.widget.NestedScrollView
    android:id="@+id/nesterScrollView"
    android:clipToPadding="false"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <android.support.v7.widget.CardView

            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:cardElevation="5dp"
            app:cardUseCompatPadding="true">

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

           <TextView
                    android:id="@+id/food_name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="8dp"
                    android:padding="12dp"
                    android:text="Food Name"
                    android:textColor="@color/colorPrimary"
                    android:textSize="20sp"
                    android:textStyle="bold" />
                <LinearLayout
                    android:orientation="horizontal"
                    android:id="@+id/layout_price"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
                    <ImageView
                        app:srcCompat="@drawable/ic_attach_money_black_24dp"
                        android:layout_weight="1"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content" />
                    <TextView
                        android:id="@+id/food_price"
                        android:layout_weight="9"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:text="1,000"
                        android:textColor="@color/colorPrimary"
                        android:textSize="18sp"
                        android:textStyle="bold" />

                </LinearLayout>

                <com.cepheuen.elegantnumberbutton.view.ElegantNumberButton
                    android:layout_width="100dp"
                    android:layout_height="30dp"
                    android:id="@+id/number_button"
                    android:layout_marginTop="8dp"
                    android:layout_marginLeft="8dp"
                    android:layout_marginBottom="18dp"
                    app:textSize="8sp"
                    app:backGroundColor="@color/colorAccent"
                    app:initialNumber="1"
                    app:finalNumber="20"
                    />

            </LinearLayout>

        </android.support.v7.widget.CardView>
        <android.support.v7.widget.CardView
            app:cardElevation="5dp"
            app:cardUseCompatPadding="true"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/food_description"
                android:layout_marginTop="12dp"
                android:lineSpacingMultiplier="1.5"
                android:padding="12dp"
                android:text="description"
                android:textColor="@android:color/black"
                android:textSize="14sp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                />

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

    </LinearLayout>
    </android.support.v4.widget.NestedScrollView>

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

如果需要任何额外的细节,我将编辑我的问题。

2 个答案:

答案 0 :(得分:1)

替换 -

android:background="@drawable/ic_shopping_cart_black_24dp"

android:src="@drawable/ic_shopping_cart_black_24dp"

FloatingActionButton中的

。您可以使用FAB将背景颜色设置为android:backgroundTint

代码就像 -

<android.support.design.widget.FloatingActionButton
    ...
    app:backgroundTint="@color/your_back_color"
    android:src="@drawable/ic_shopping_cart_black_24dp" />

如果您使用的是矢量绘图,android:src将替换为app:srcCompat

答案 1 :(得分:0)

不确定,但android:fitsSystemWindows只应分配给一个元素,而且,它通常分配给根元素:在这种情况下CoordinatorLayout

可能会出现问题,尤其是如果您使用库为KitKat(API 19)上的状态栏着色,该状态栏本身不支持它。