0

如何为 API 8 及更高版本的导航抽屉添加向后兼容性。

日志猫:

11-11 16:12:31.796: E/AndroidRuntime(621): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.android.navigationdrawerexample/com.example.android.navigationdrawerexample.MainActivity}: java.lang.ClassNotFoundException: com.example.android.navigationdrawerexample.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.android.navigationdrawerexample-2.apk]
11-11 16:12:31.796: E/AndroidRuntime(621):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
11-11 16:12:31.796: E/AndroidRuntime(621):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-11 16:12:31.796: E/AndroidRuntime(621):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-11 16:12:31.796: E/AndroidRuntime(621):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-11 16:12:31.796: E/AndroidRuntime(621):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-11 16:12:31.796: E/AndroidRuntime(621):  at android.os.Looper.loop(Looper.java:123)
11-11 16:12:31.796: E/AndroidRuntime(621):  at android.app.ActivityThread.main(ActivityThread.java:4627)
11-11 16:12:31.796: E/AndroidRuntime(621):  at java.lang.reflect.Method.invokeNative(Native Method)
11-11 16:12:31.796: E/AndroidRuntime(621):  at java.lang.reflect.Method.invoke(Method.java:521)
11-11 16:12:31.796: E/AndroidRuntime(621):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-11 16:12:31.796: E/AndroidRuntime(621):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-11 16:12:31.796: E/AndroidRuntime(621):  at dalvik.system.NativeStart.main(Native Method)
11-11 16:12:31.796: E/AndroidRuntime(621): Caused by: java.lang.ClassNotFoundException: com.example.android.navigationdrawerexample.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.android.navigationdrawerexample-2.apk]
11-11 16:12:31.796: E/AndroidRuntime(621):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
11-11 16:12:31.796: E/AndroidRuntime(621):  at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
11-11 16:12:31.796: E/AndroidRuntime(621):  at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
11-11 16:12:31.796: E/AndroidRuntime(621):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
11-11 16:12:31.796: E/AndroidRuntime(621):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
11-11 16:12:31.796: E/AndroidRuntime(621):  ... 11 more
4

2 回答 2

1

请参阅此链接最适合导航抽屉的向后兼容性

https://github.com/BradleyRL/NavDrawerExampleAppCompat-v7

于 2013-11-11T11:57:06.887 回答
0

我使用 actionbarsherlock 库来获得向后兼容性:

  • 导入 sherlockak 导航抽屉。

  • 导入 actionbarsherlock。

请参阅本教程进行设置。

编辑:

不使用 actionbarsherlock 库:

于 2013-11-11T10:16:02.550 回答