我正在尝试按照本指南实施Android导航抽屉:
http://codetheory.in/android-navigation-drawer/
我收到了以下错误:
07-06 11:59:06.125: E/AndroidRuntime(1878): FATAL EXCEPTION: main
07-06 11:59:06.125: E/AndroidRuntime(1878): Process: com.example.app, PID: 1878
07-06 11:59:06.125: E/AndroidRuntime(1878): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/com.example.app.Home}: android.view.InflateException: Binary XML file line #1: Error inflating class DrawerLayout
07-06 11:59:06.125: E/AndroidRuntime(1878): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
07-06 11:59:06.125: E/AndroidRuntime(1878): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
07-06 11:59:06.125: E/AndroidRuntime(1878): at android.app.ActivityThread.access$800(ActivityThread.java:135)
07-06 11:59:06.125: E/AndroidRuntime(1878): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
07-06 11:59:06.125: E/AndroidRuntime(1878): at android.os.Handler.dispatchMessage(Handler.java:102)
07-06 11:59:06.125: E/AndroidRuntime(1878): at android.os.Looper.loop(Looper.java:136)
07-06 11:59:06.125: E/AndroidRuntime(1878): at android.app.ActivityThread.main(ActivityThread.java:5001)
07-06 11:59:06.125: E/AndroidRuntime(1878): at java.lang.reflect.Method.invokeNative(Native Method)
07-06 11:59:06.125: E/AndroidRuntime(1878): at java.lang.reflect.Method.invoke(Method.java:515)
07-06 11:59:06.125: E/AndroidRuntime(1878): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
07-06 11:59:06.125: E/AndroidRuntime(1878): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
07-06 11:59:06.125: E/AndroidRuntime(1878): at dalvik.system.NativeStart.main(Native Method)
07-06 11:59:06.125: E/AndroidRuntime(1878): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class DrawerLayout
07-06 11:59:06.125: E/AndroidRuntime(1878): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
07-06 11:59:06.125: E/AndroidRuntime(1878): at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
07-06 11:59:06.125: E/AndroidRuntime(1878): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
07-06 11:59:06.125: E/AndroidRuntime(1878): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
07-06 11:59:06.125: E/AndroidRuntime(1878): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
07-06 11:59:06.125: E/AndroidRuntime(1878): at android.app.Activity.setContentView(Activity.java:1929)
07-06 11:59:06.125: E/AndroidRuntime(1878): at com.example.app.Home.onCreate(Home.java:125)
07-06 11:59:06.125: E/AndroidRuntime(1878): at android.app.Activity.performCreate(Activity.java:5231)
07-06 11:59:06.125: E/AndroidRuntime(1878): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-06 11:59:06.125: E/AndroidRuntime(1878): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
07-06 11:59:06.125: E/AndroidRuntime(1878): ... 11 more
07-06 11:59:06.125: E/AndroidRuntime(1878): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.DrawerLayout" on path: DexPathList[[zip file "/data/app/com.example.app-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.app-2, /system/lib]]
07-06 11:59:06.125: E/AndroidRuntime(1878): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
07-06 11:59:06.125: E/AndroidRuntime(1878): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
07-06 11:59:06.125: E/AndroidRuntime(1878): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
07-06 11:59:06.125: E/AndroidRuntime(1878): at android.view.LayoutInflater.createView(LayoutInflater.java:559)
07-06 11:59:06.125: E/AndroidRuntime(1878): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:652)
07-06 11:59:06.125: E/AndroidRuntime(1878): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
07-06 11:59:06.125: E/AndroidRuntime(1878): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
07-06 11:59:06.125: E/AndroidRuntime(1878): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
07-06 11:59:06.125: E/AndroidRuntime(1878): ... 20 more
在我的源代码行#125中:
setContentView(R.layout.ss_home);
R.layout.ss_home的内容是:
<DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="00dp"
android:layout_marginTop="0dp"
android:orientation="vertical"
android:id="@+id/RootView" >
<RelativeLayout
android:layout_width="280dp"
android:layout_height="match_parent"
android:id="@+id/drawerPane"
android:layout_gravity="start">
...
如果有人能够阐明为什么会发生这种情况/如何解决它 - 我们将不胜感激。
我对这一点感到困惑(它说的资源缺失 - 存在![也 - 我已经尝试清理项目并重新启动Eclipse])
答案 0 :(得分:2)
关于XML的变化,
<DrawerLayout
至<android.support.v4.widget.DrawerLayout
并且不要忘记集成支持库
答案 1 :(得分:0)
在迁移到androidx时,您可能会错过一些类迁移。 对我来说,我正在使用旧的支持类而不是androidx类作为该组件
android:appComponentFactory="androidx.core.app.CoreComponentFactory".
检查其他andoridx类here。