活动在api 19中崩溃,在api 25中它显示出突然的行为

时间:2018-05-06 07:50:27

标签: android android-layout android-resources

这是调试报告inn api 19 emulator ..

   Caused by: android.view.InflateException: Binary XML file line #47: Error inflating class <unknown>
                                                                             at android.view.LayoutInflater.createView(LayoutInflater.java:620)
                                                                             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: java.lang.reflect.InvocationTargetException
                                                                             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: 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.widget.ImageView.<init>(ImageView.java:129)
                                                                             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.widget.ImageView.<init>(ImageView.java:129) 
                                                                             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) 
 05-06 15:36:10.141 468-503/system_process E/InputDispatcher: channel '52947f70 com.example.admin.clicknorder/com.example.admin.clicknorder.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
05-06 15:36:10.141 468-503/system_process E/InputDispatcher: channel '52a636f8 com.example.admin.clicknorder/com.example.admin.clicknorder.Home (server)' ~ Channel is unrecoverably broken and will be disposed!
05-06 15:36:10.141 468-503/system_process E/InputDispatcher: channel '52a783c8 com.example.admin.clicknorder/com.example.admin.clicknorder.FoodList (server)' ~ Channel is unrecoverably broken and will be disposed!
05-06 15:36:10.285 5612-5612/com.example.admin.clicknorder E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
05-06 15:36:10.345 5612-5612/com.example.admin.clicknorder E/AndroidRuntime: FATAL EXCEPTION: main
                                                                         Process: com.example.admin.clicknorder, PID: 5612
                                                                         java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.admin.clicknorder/com.example.admin.clicknorder.Home}: java.lang.NullPointerException
                                                                             at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
                                                                             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: java.lang.NullPointerException
                                                                             at com.example.admin.clicknorder.Home.onCreate(Home.java:78)
                                                                             at android.app.Activity.performCreate(Activity.java:5231)

这就是来自fooddetails.java的错误

 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_food_detail);
 database=FirebaseDatabase.getInstance();
 foods=database.getReference("Food");

此foodetail.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:fitsSystemWindows="true">

<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.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing"
        android:layout_width="match_parent"
        android:layout_height="350dp"
        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"
    app:srcCompact="@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>

如果需要更多详细信息,我会编辑我的问题。谢谢

1 个答案:

答案 0 :(得分:1)

正如我在日志中看到的那样,您在FloatingActionButton上的标识为R.id.btnCart

时遇到了麻烦
android.content.res.Resources$NotFoundException: File res/drawable/ic_shopping_cart_black_24dp.xml from drawable resource ID #0x7f020068 at 
...

Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag vector at 
...

Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method 

可能是您制作了印刷错误,将app:srcCompact更改为app:srcCompat会解决问题