简体   繁体   English

Robolectric测试针对android.support.v4.widget.DrawerLayout运行InflateException

[英]Robolectric test run InflateException for android.support.v4.widget.DrawerLayout

I'm using Robolectric head and am targeting Android 14 and have it and am using Android 18 to compile the module. 我正在使用Robolectric头,目标是Android 14,并已将其用于Android 18来编译模块。 You can see the commented LinearLayout which works under test below. 您可以在下面的测试中看到带有注释的LinearLayout。 I'm attempting to inflate the following. 我正在尝试以下内容。 I have the v4 support jar marked as "compile" in IntelliJ. 我在IntelliJ中将v4支持jar标记为“编译”。 Not sure what else to share, but I would greatly appreciate any recommendations. 不知道还有什么要分享的,但是我将不胜感激任何建议。

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

<!--<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"-->
<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:id="@+id/drawer"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    ...

and getting 并得到

android.view.InflateException: XML file ./res/layout/timeline_activity.xml line #-1 (sorry, not yet implemented): Error inflating class <unknown>
    at android.view.LayoutInflater.createView(LayoutInflater.java:613)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
    at android.app.Activity.setContentView(Activity.java:1867)
    at com.whistle.bigdog.ui.timeline.TimelineActivity.onCreate(TimelineActivity.java:46)
    at android.app.Activity.performCreate(Activity.java:5008)
    at org.fest.reflect.method.Invoker.invoke(Invoker.java:112)
    at org.robolectric.util.ActivityController$1.run(ActivityController.java:154)
    at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:257)
    at org.robolectric.util.ActivityController.create(ActivityController.java:149)
    at org.robolectric.util.ActivityController.create(ActivityController.java:161)
    at com.whistle.bigdog.ui.timeline.TimelineActivityTest.setUp(TimelineActivityTest.java:69)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
    at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:236)
    at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.junit.runners.Suite.runChild(Suite.java:128)
    at org.junit.runners.Suite.runChild(Suite.java:24)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:202)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:65)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_createView(LayoutInflater.java:587)
    at android.view.LayoutInflater.createView(LayoutInflater.java)
    at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_createViewFromTag(LayoutInflater.java:687)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java)
    at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_inflate(LayoutInflater.java:466)
    at android.view.LayoutInflater.inflate(LayoutInflater.java)
    at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_inflate(LayoutInflater.java:396)
    at android.view.LayoutInflater.inflate(LayoutInflater.java)
    at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_inflate(LayoutInflater.java:352)
    at android.view.LayoutInflater.inflate(LayoutInflater.java)
    at com.android.internal.policy.impl.PhoneWindow.$$robo$$PhoneWindow_1a87_setContentView(PhoneWindow.java:256)
    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java)
    at android.app.Activity.$$robo$$Activity_c57b_setContentView(Activity.java:1867)
    at android.app.Activity.setContentView(Activity.java)
    at com.whistle.bigdog.ui.timeline.TimelineActivity.onCreate(TimelineActivity.java:46)
    at android.app.Activity.$$robo$$Activity_c57b_performCreate(Activity.java:5008)
    at android.app.Activity.performCreate(Activity.java)
    at sun.reflect.GeneratedMethodAccessor110.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at org.fest.reflect.method.Invoker.invoke(Invoker.java:112)
    at org.robolectric.util.ActivityController$1.run(ActivityController.java:154)
    at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:257)
    at org.robolectric.util.ActivityController.create(ActivityController.java:149)
    at org.robolectric.util.ActivityController.create(ActivityController.java:161)
    at com.whistle.bigdog.ui.timeline.TimelineActivityTest.setUp(TimelineActivityTest.java:69)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
    at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:236)
    at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.junit.runners.Suite.runChild(Suite.java:128)
    at org.junit.runners.Suite.runChild(Suite.java:24)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:202)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:65)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    ... 1 more
Caused by: java.lang.NoSuchMethodError: android.support.v4.widget.ScrollerCompat.create(Landroid/content/Context;Landroid/view/animation/Interpolator;)Landroid/support/v4/widget/ScrollerCompat;
    at android.support.v4.widget.ViewDragHelper.__constructor__(ViewDragHelper.java:391)
    at android.support.v4.widget.ViewDragHelper.<init>(ViewDragHelper.java:373)
    at android.support.v4.widget.ViewDragHelper.create(ViewDragHelper.java:347)
    at android.support.v4.widget.ViewDragHelper.create(ViewDragHelper.java:360)
    at android.support.v4.widget.DrawerLayout.__constructor__(DrawerLayout.java:234)
    at android.support.v4.widget.DrawerLayout.<init>(DrawerLayout.java:225)
    at android.support.v4.widget.DrawerLayout.<init>(DrawerLayout.java:221)
    at android.view.LayoutInflater.createView(LayoutInflater.java:587)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
    at android.app.Activity.setContentView(Activity.java:1867)
    at com.whistle.bigdog.ui.timeline.TimelineActivity.onCreate(TimelineActivity.java:46)
    at android.app.Activity.performCreate(Activity.java:5008)
    at org.fest.reflect.method.Invoker.invoke(Invoker.java:112)
    at org.robolectric.util.ActivityController$1.run(ActivityController.java:154)
    at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:257)
    at org.robolectric.util.ActivityController.create(ActivityController.java:149)
    at org.robolectric.util.ActivityController.create(ActivityController.java:161)
    at com.whistle.bigdog.ui.timeline.TimelineActivityTest.setUp(TimelineActivityTest.java:69)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
    at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:236)
    at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:177)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.junit.runners.Suite.runChild(Suite.java:128)
    at org.junit.runners.Suite.runChild(Suite.java:24)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:65)
    ... 1 more

I figured it out... it was all just ordering of libraries in the modules configuration. 我知道了...所有这些只是模块配置中的库排序。 It was pretty confusing because I had another Android library for Facebook integration which was also using the v4 jar and it was above robolectric. 这非常令人困惑,因为我还有另一个用于Facebook集成的Android库,该库也使用了v4 jar,它位于robolectric之上。

My final ordering: 我的最终订购:

<Module source>
junit.jar
other_random.jar
etc.jar
robolectric
Facebook Android Library
Android v4 support jar
Android 4.4 Platform

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 android.support.v4.widget.DrawerLayout无法转换为android.support.v4.widget.DrawerLayout $ DrawerListener - android.support.v4.widget.DrawerLayout cannot be cast to android.support.v4.widget.DrawerLayout$DrawerListener 找不到java android.support.v4.widget.DrawerLayout - java android.support.v4.widget.DrawerLayout not being found android.support.v4.widget.DrawerLayout无法实例化 - android.support.v4.widget.DrawerLayout Cannot be instantiated (android.support.v4.widget.DrawerLayout $ DrawerListener)&#39;在空对象引用上 - (android.support.v4.widget.DrawerLayout$DrawerListener)' on a null object reference 找不到从方法android.support.v4.widget.DrawerLayout引用的类&#39;android.support.v4.widget.DrawerLayout $ 1&#39; - Could not find class 'android.support.v4.widget.DrawerLayout$1', referenced from method android.support.v4.widget.DrawerLayout android.support.constraint.ConstraintLayout无法转换为android.support.v4.widget.DrawerLayout - android.support.constraint.ConstraintLayout cannot be cast to android.support.v4.widget.DrawerLayout 运行代码时,我的应用程序崩溃。 错误是:“ android.widget.SlidingDrawer无法转换为android.support.v4.widget.Drawerlayout” - My app crashes when i run the code. ERROR Is: “ android.widget.SlidingDrawer cannot be cast to android.support.v4.widget.Drawerlayout” ClassCastException:java.lang.ClassCastException:android.widget.LinearLayout $ LayoutParams无法强制转换为android.support.v4.widget.DrawerLayout - ClassCastException : java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.support.v4.widget.DrawerLayout 创建导航抽屉时出现致命错误-RelativeLayout $ LayoutParams无法转换为android.support.v4.widget.DrawerLayout $ LayoutParams - Fatal Error When Creating Navigation Drawer - RelativeLayout$LayoutParams cannot be cast to android.support.v4.widget.DrawerLayout$LayoutParams 如何在具有android.support.v7.widget.CardView的情况下使用robolectric测试活动? - How to test an activity with robolectric while it has android.support.v7.widget.CardView?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM