好的,这是一个有趣的:我正在使用Android Studio 1.1.0,我有一个Android应用程序和一个相关的Android Wear应用程序,我正在尝试在智能手表设备上进行测试。我将我在Android应用程序中使用的类文件放入Android库模块,然后将其作为依赖项添加到我的Android Wear应用程序中。该应用程序构建并部署到智能手表上,但当它运行时,我得到以下异常和堆栈跟踪。任何建议,将不胜感激。谢谢!
04-17 21:55:45.764 7759-7759/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.myapp.wear, PID: 7759
android.view.InflateException: Binary XML file line #12: Error inflating class android.support.wearable.view.WearableListView
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.wearable.view.WatchViewStub.inflate(WatchViewStub.java:179)
at android.support.wearable.view.WatchViewStub.onApplyWindowInsets(WatchViewStub.java:148)
at android.view.View.dispatchApplyWindowInsets(View.java:6514)
at android.view.ViewGroup.dispatchApplyWindowInsets(ViewGroup.java:5782)
at android.view.ViewGroup.dispatchApplyWindowInsets(ViewGroup.java:5786)
at android.view.ViewGroup.dispatchApplyWindowInsets(ViewGroup.java:5786)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchApplyWindowInsets(PhoneWindow.java:2333)
at android.view.ViewRootImpl.dispatchApplyInsets(ViewRootImpl.java:1205)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1423)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1054)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5779)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.wearable.view.WatchViewStub.inflate(WatchViewStub.java:179)
at android.support.wearable.view.WatchViewStub.onApplyWindowInsets(WatchViewStub.java:148)
at android.view.View.dispatchApplyWindowInsets(View.java:6514)
at android.view.ViewGroup.dispatchApplyWindowInsets(ViewGroup.java:5782)
at android.view.ViewGroup.dispatchApplyWindowInsets(ViewGroup.java:5786)
at android.view.ViewGroup.dispatchApplyWindowInsets(ViewGroup.java:5786)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchApplyWindowInsets(PhoneWindow.java:2333)
at android.view.ViewRootImpl.dispatchApplyInsets(ViewRootImpl.java:1205)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1423)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1054)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5779)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/util/ArrayMap;
at android.support.v7.widget.RecyclerView$State.<init>(RecyclerView.java:7461)
at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:233)
at android.support.wearable.view.WearableListView.<init>(WearableListView.java:151)
at android.support.wearable.view.WearableListView.<init>(WearableListView.java:147)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.wearable.view.WatchViewStub.inflate(WatchViewStub.java:179)
at android.support.wearable.view.WatchViewStub.onApplyWindowInsets(WatchViewStub.java:148)
at android.view.View.dispatchApplyWindowInsets(View.java:6514)
at android.view.ViewGroup.dispatchApplyWindowInsets(ViewGroup.java:5782)
at android.view.ViewGroup.dispatchApplyWindowInsets(ViewGroup.java:5786)
at android.view.ViewGroup.dispatchApplyWindowInsets(ViewGroup.java:5786)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchApplyWindowInsets(PhoneWindow.java:2333)
at android.view.ViewRootImpl.dispatchApplyInsets(ViewRootImpl.java:1205)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1423)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1054)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5779)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.util.ArrayMap" on path: DexPathList[[zip file "/data/app/com.myapp.wear-1/base.apk"],nativeLibraryDirectories=[/data/app/com.myapp.wear-1/lib/arm, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.support.v7.widget.RecyclerView$State.<init>(RecyclerView.java:7461)
at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:233)
at android.support.wearable.view.WearableListView.<init>(WearableListView.java:151)
at android.support.wearable.view.WearableListView.<init>(WearableListView.java:147)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.wearable.view.WatchViewStub.inflate(WatchViewStub.java:179)
at android.support.wearable.view.WatchViewStub.onApplyWindowInsets(WatchViewStub.java:148)
at android.view.View.dispatchApplyWindowInsets(View.java:6514)
at android.view.ViewGroup.dispatchApplyWindowInsets(ViewGroup.java:5782)
at android.view.ViewGroup.dispatchApplyWindowInsets(ViewGroup.java:5786)
at android.view.ViewGroup.dispatchApplyWindowInsets(ViewGroup.java:5786)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchApplyWindowInsets(PhoneWindow.java:2333)
at android.view.ViewRootImpl.dispatchApplyInsets(ViewRootImpl.java:1205)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1423)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1054)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5779)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Suppressed: java.lang.ClassNotFoundException: android.support.v4.util.ArrayMap
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 36 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
以下是gradle配置和模块的视觉效果:
答案 0 :(得分:1)
我在你的logcat跟踪中看到了这个java.lang.ClassNotFoundException: android.support.v4.util.ArrayMap
。我想也许v4
和v7
的版本会导致此错误。您的v4
和v7
支持库是最新的吗?而BTW,ArrayMap
仅可用于Android API 21+
答案 1 :(得分:1)
在我的情况下,我通过删除 android-support-v4.jar 解决了这个问题,因为它已经过时并且实际上并没有 ArrayMap.class 而我放了一个来自我的lib文件夹中的 \ extras \ android \ support \ v4 然后将其添加到Java构建路径,它最终工作。 希望它有所帮助:)
答案 2 :(得分:0)
您可以找到此错误的解决方案here。
错误非常明显(基本上缺少ArrayMap
):
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/util/ArrayMap;
这是因为支持库版本旧,而另一个库(可能是Google Play服务)在其上找不到ArrayMap
。
解决方案是将支持库升级到包含ArrayMap
的新版本。这就是我所做的并且有效。
此外,根据linked solution您还应该:
确保您的
compileSdkVersion
与主要版本号匹配 依赖