使用协调器布局创建活动时出错

时间:2018-04-25 22:15:22

标签: android xml layout dependencies android-coordinatorlayout

只是搞乱各种布局,并想知道为什么这种布局不起作用。我下载了正确的依赖项,但仍然出错。我想使用这种布局,因为我读到你可以用它定位Snackbar。所有其他布局都在Android工作室中工作,除了这个。以下有关协调器布局的教程可以轻松使用它们,而不会出现任何错误。

布局

<?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="maginatestudios.com.maginatecrate.test">

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

的build.gradle

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.google.firebase:firebase-auth:15.0.0'
implementation 'com.google.android.gms:play-services-auth:15.0.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support:recyclerview-v7:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

错误日志

04-25 18:04:43.544 6329-6329/? E/AndroidRuntime: FATAL EXCEPTION: main
                                             Process: maginatestudios.com.maginatecrate, PID: 6329
                                             java.lang.RuntimeException: Unable to start activity ComponentInfo{maginatestudios.com.maginatecrate/maginatestudios.com.maginatecrate.test}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.support.design.widget.CoordinatorLayout
                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                 at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                 at android.os.Handler.dispatchMessage(Handler.java:105)
                                                 at android.os.Looper.loop(Looper.java:164)
                                                 at android.app.ActivityThread.main(ActivityThread.java:6540)
                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                 at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                                              Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.support.design.widget.CoordinatorLayout
                                              Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class android.support.design.widget.CoordinatorLayout
                                              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:650)
                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:793)
                                                 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:733)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                 at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
                                                 at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:418)
                                                 at android.app.Activity.setContentView(Activity.java:2653)
                                                 at maginatestudios.com.maginatecrate.test.onCreate(test.java:11)
                                                 at android.app.Activity.performCreate(Activity.java:6980)
                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
                                                 at android.app.ActivityThread.-wrap11(Unknown Source:0)
                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
                                                 at android.os.Handler.dispatchMessage(Handler.java:105)
                                                 at android.os.Looper.loop(Looper.java:164)
                                                 at android.app.ActivityThread.main(ActivityThread.java:6540)
                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                 at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
                                              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.CoordinatorLayout.<init>(CoordinatorLayout.java:206)
                                                 at android.support.design.widget.CoordinatorLayout.<init>(CoordinatorLayout.java:200)

1 个答案:

答案 0 :(得分:0)

尝试删除:

df[i, 'var2']

编辑,我的不好只是看到那里的错误

尝试让您的活动延伸

<?xml version="1.0" encoding="utf-8"?>