应用程序因浮动操作按钮而停止

时间:2018-05-11 05:58:32

标签: android floating-action-button

我的应用程序在将其连接到android studio的移动设备上启动后不断停止。

下面是我的日志文件,显示以下错误。基本上我理解的是错误是因为我在main_activity.xml文件中使用的浮动操作按钮

我无法弄清楚导致错误的确切原因。 我甚至添加了库&com; android.support:design:26.1.0'。

05-11 11:18:01.098 27456-27456/it.moondroid.chatbot E/AndroidRuntime: FATA          L EXCEPTION: main
         Process: it.moondroid.chatbot, PID: 27456
        java.lang.RuntimeException: Unable to start activity ComponentInfo{it.moondroid.chatbot/it.moondroid.chatbot.MainActivity}: android.view.InflateException: Binary XML file line #39: Binary XML file line #39: Error inflating class android.support.design.widget.FloatingActionButton
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2957)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6940)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
     Caused by: android.view.InflateException: Binary XML file line #39: Binary XML file line #39: Error inflating class android.support.design.widget.FloatingActionButton
     Caused by: android.view.InflateException: Binary XML file line #39: Error inflating class android.support.design.widget.FloatingActionButton
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
        at android.view.LayoutInflater.createView(LayoutInflater.java:647)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
        at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:461)
        at android.app.Activity.setContentView(Activity.java:2737)
        at it.moondroid.chatbot.MainActivity.onCreate(MainActivity.java:47)
        at android.app.Activity.performCreate(Activity.java:7174)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2910)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6940)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
     Caused by: java.lang.IllegalArgumentException: You need to use a Theme.AppCompat theme (or descendant) with the design library.
        at android.support.design.widget.ThemeUtils.checkAppCompatTheme(ThemeUtils.java:33)
        at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:157)
        at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:151)
        at java.lang.reflect.Constructor.newInstance0(Native Method) 
        at java.lang.reflect.Constructor.newInstance(Constructor.java:334) 
        at android.view.LayoutInflater.createView(LayoutInflater.java:647) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730) 
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:863) 
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) 
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:866) 
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
        at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:461) 
        at android.app.Activity.setContentView(Activity.java:2737) 
        at it.moondroid.chatbot.MainActivity.onCreate(MainActivity.java:47) 
        at android.app.Activity.performCreate(Activity.java:7174) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2910) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032) 
        at android.app.ActivityThread.-wrap11(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696) 
        at android.os.Handler.dispatchMessage(Handler.java:105) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6940) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

下面是我的xml文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background_hd" >

    <ListView
        android:id="@+id/chat_listView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/form"
        android:layout_alignParentTop="true"
        android:clipToPadding="false"
        android:divider="@android:color/transparent"
        android:dividerHeight="1dp"
        android:listSelector="@android:color/transparent"
        android:transcriptMode="alwaysScroll" >
    </ListView>

    <RelativeLayout
        android:id="@+id/form"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true"
        android:background="@android:color/white"
        android:padding="16dp">

        <EditText
            android:id="@+id/chat_editText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_marginRight="82dp"
            android:inputType="text" />

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_centerVertical="true"
            android:layout_marginEnd="13dp"
            android:clickable="true"
            android:focusable="true"
            android:src="@android:drawable/ic_btn_speak_now"
            app:fabSize="mini" />

        </RelativeLayout>

    </RelativeLayout>

1 个答案:

答案 0 :(得分:1)

如错误日志中所述&#34;您需要将Theme.AppCompat主题(或后代)与设计库&#34;。

一起使用

由于