我已经研究了其余的答案,但是它们似乎都建议更新依赖项等。但是,我正在为SDK 28开发,所有内容都是最新的,并且已经通过Android Studio进行了检查,因此似乎是另一个原因。
基本上,我已经通过XML添加了一个浮动操作按钮:
<android.support.design.widget.FloatingActionButton
android:id="@+id/dict_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:src="@drawable/ic_add_circle_black_24dp"
android:layout_margin="16dp" />
当我尝试加载包含FAB的活动时,出现以下崩溃。
--------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: main
Process: uk.ac.aber.dcs.haa14.assignment, PID: 2876
java.lang.RuntimeException: Unable to start activity ComponentInfo{uk.ac.aber.dcs.haa14.assignment/uk.ac.aber.dcs.haa14.assignment.ui.DictionaryActivity}: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class android.support.design.widget.FloatingActionButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class android.support.design.widget.FloatingActionButton
Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class android.support.design.widget.FloatingActionButton
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.widget.FloatingActionButton" on path: DexPathList[[zip file "/data/app/uk.ac.aber.dcs.haa14.assignment-5Y5qp-mx6ITFeGrYdObqMQ==/base.apk", zip file "/data/app/uk.ac.aber.dcs.haa14.assignment-5Y5qp-mx6ITFeGrYdObqMQ==/split_lib_dependencies_apk.apk", zip file "/data/app/uk.ac.aber.dcs.haa14.assignment-5Y5qp-mx6ITFeGrYdObqMQ==/split_lib_resources_apk.apk", zip file "/data/app/uk.ac.aber.dcs.haa14.assignment-5Y5qp-mx6ITFeGrYdObqMQ==/split_lib_slice_0_apk.apk", zip file "/data/app/uk.ac.aber.dcs.haa14.assignment-5Y5qp-mx6ITFeGrYdObqMQ==/split_lib_slice_1_apk.apk", zip file "/data/app/uk.ac.aber.dcs.haa14.assignment-5Y5qp-mx6ITFeGrYdObqMQ==/split_lib_slice_2_apk.apk", zip file "/data/app/uk.ac.aber.dcs.haa14.assignment-5Y5qp-mx6ITFeGrYdObqMQ==/split_lib_slice_3_apk.apk", zip file "/data/app/uk.ac.aber.dcs.haa14.assignment-5Y5qp-mx6ITFeGrYdObqMQ==/split_lib_slice_4_apk.apk", zip file "/data/app/uk.ac.aber.dcs.haa14.assignment-5Y5qp-mx6ITFeGrYdObqMQ==/split_lib_slice_5_apk.apk", zip file "/data/app/uk.ac.aber.dcs.haa14.assignment-5Y5qp-mx6ITFeGrYdObqMQ==/split_lib_slice_6_apk.apk", zip file "/data/app/uk.ac.aber.dcs.haa14.assignment-5Y5qp-mx6ITFeGrYdObqMQ==/split_lib_slice_7_apk.apk", zip file "/data/app/uk.ac.aber.dcs.haa14.assignment-5Y5qp-mx6ITFeGrYdObqMQ==/split_lib_slice_8_apk.apk", zip file "/data/app/uk.ac.aber.dcs.haa14.assignment-5Y5qp-mx6ITFeGrYdObqMQ==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/uk.ac.aber.dcs.haa14.assignment-5Y5qp-mx6ITFeGrYdObqMQ==/lib/x86, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.view.LayoutInflater.createView(LayoutInflater.java:606)
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.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at uk.ac.aber.dcs.haa14.assignment.ui.DictionaryActivity.onCreate(DictionaryActivity.java:32)
E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:7009)
at android.app.Activity.performCreate(Activity.java:7000)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Suppressed: java.io.IOException: No original dex files found for dex location /data/app/uk.ac.aber.dcs.haa14.assignment-5Y5qp-mx6ITFeGrYdObqMQ==/split_lib_resources_apk.apk
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:353)
at dalvik.system.DexFile.<init>(DexFile.java:100)
at dalvik.system.DexFile.<init>(DexFile.java:74)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:374)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:337)
at dalvik.system.DexPathList.<init>(DexPathList.java:157)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:73)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:88)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:69)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:35)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:693)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:727)
at android.app.LoadedApk.getResources(LoadedApk.java:954)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2270)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5639)
at android.app.ActivityThread.-wrap1(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
... 6 more
应用程序终止。
答案 0 :(得分:1)
将implementation 'com.android.support:design:27.1.0'
添加到所有其他依赖项所在的app / build.gradle中。