如何使用Robolectric 2.2测试ListView?它说android.widget.ListView尚未实现

如何使用Robolectric 2.2测试ListView?它说android.widget.ListView尚未实现,android,listview,android-listview,robolectric,Android,Listview,Android Listview,Robolectric,当我在ListActivity上使用Robolectric 2.2运行JUnit测试时,我得到一个膨胀异常,表示ListView没有实现。我该怎么做?我一直在研究如何使用.shadowOf(),但我不确定如何使用 以下是堆栈跟踪: android.view.InflateException: XML file ./res/layout/activity_main.xml line #-1 (sorry, not yet implemented): Error inflating class an

当我在ListActivity上使用Robolectric 2.2运行JUnit测试时,我得到一个膨胀异常,表示ListView没有实现。我该怎么做?我一直在研究如何使用.shadowOf(),但我不确定如何使用

以下是堆栈跟踪:

android.view.InflateException: XML file ./res/layout/activity_main.xml line #-1 (sorry, not yet implemented): Error inflating class android.widget.ListView at android.view.LayoutInflater.createView(LayoutInflater.java:613) at org.robolectric.shadows.RoboLayoutInflater.onCreateView(RoboLayoutInflater.java:38) at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685) at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 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.jch.latransit.MainActivity.onCreate(MainActivity.java:43) 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:116) at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:256) at org.robolectric.util.ActivityController.create(ActivityController.java:111) at org.robolectric.util.ActivityController.create(ActivityController.java:123) at com.jch.latransit.domain.TestTimeStamp.setUp(TestTimeStamp.java:33) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30) at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:234) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:175) at org.junit.runners.ParentRunner.run(ParentRunner.java:300) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_createView(LayoutInflater.java:587) at android.view.LayoutInflater.createView(LayoutInflater.java) at org.robolectric.shadows.RoboLayoutInflater.onCreateView(RoboLayoutInflater.java:38) at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_onCreateView(LayoutInflater.java:660) at android.view.LayoutInflater.onCreateView(LayoutInflater.java) at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_createViewFromTag(LayoutInflater.java:685) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java) at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_rInflate(LayoutInflater.java:746) at android.view.LayoutInflater.rInflate(LayoutInflater.java) at android.view.LayoutInflater.$$robo$$LayoutInflater_1d1f_inflate(LayoutInflater.java:489) 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.jch.latransit.MainActivity.onCreate(MainActivity.java:43) at android.app.Activity.$$robo$$Activity_c57b_performCreate(Activity.java:5008) at android.app.Activity.performCreate(Activity.java) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.fest.reflect.method.Invoker.invoke(Invoker.java:112) at org.robolectric.util.ActivityController$1.run(ActivityController.java:116) at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:256) at org.robolectric.util.ActivityController.create(ActivityController.java:111) at org.robolectric.util.ActivityController.create(ActivityController.java:123) at com.jch.latransit.domain.TestTimeStamp.setUp(TestTimeStamp.java:33) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) ... 23 more Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -9 at java.lang.String.substring(String.java:1911) at org.robolectric.res.ResName.qualifyResName(ResName.java:50) at org.robolectric.res.Attribute.getResourceReference(Attribute.java:138) at org.robolectric.res.Attribute.qualifiedValue(Attribute.java:127) at org.robolectric.res.builder.XmlFileBuilder$XmlResourceParserImpl.qualify(XmlFileBuilder.java:316) at org.robolectric.res.builder.XmlFileBuilder$XmlResourceParserImpl.getAttributeValue(XmlFileBuilder.java:340) at org.robolectric.shadows.ShadowResources.findAttributeValue(ShadowResources.java:257) at org.robolectric.shadows.ShadowResources.attrsToTypedArray(ShadowResources.java:193) at org.robolectric.shadows.ShadowResources.access$000(ShadowResources.java:52) at org.robolectric.shadows.ShadowResources$ShadowTheme.obtainStyledAttributes(ShadowResources.java:465) at android.content.res.Resources$Theme.obtainStyledAttributes(Resources.java) at android.content.Context.obtainStyledAttributes(Context.java:374) at android.view.View.__constructor__(View.java:3297) at org.fest.reflect.method.Invoker.invoke(Invoker.java:112) at org.robolectric.shadows.ShadowView.__constructor__(ShadowView.java:61) at android.view.View.(View.java:3295) at android.view.ViewGroup.(ViewGroup.java:427) at android.widget.AdapterView.(AdapterView.java:235) at android.widget.AbsListView.(AbsListView.java:758) at android.widget.ListView.(ListView.java:141) at android.widget.ListView.(ListView.java:137) at android.view.LayoutInflater.createView(LayoutInflater.java:587) at org.robolectric.shadows.RoboLayoutInflater.onCreateView(RoboLayoutInflater.java:38) at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685) at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 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.jch.latransit.MainActivity.onCreate(MainActivity.java:43) 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:116) at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:256) at org.robolectric.util.ActivityController.create(ActivityController.java:111) at org.robolectric.util.ActivityController.create(ActivityController.java:123) at com.jch.latransit.domain.TestTimeStamp.setUp(TestTimeStamp.java:33) ... 23 more android.view.InflateException:XML文件/res/layout/activity_main.XML行#-1(抱歉,尚未实现):对类android.widget.ListView进行充气时出错 在android.view.LayoutInflater.createView中(LayoutInflater.java:613) 位于org.robollectric.shadows.robolayoutfillater.onCreateView(robolayoutfillater.java:38) 位于android.view.LayoutInflater.onCreateView(LayoutInflater.java:660) 位于android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685) 位于android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 在android.view.LayoutInflater.充气(LayoutInflater.java:489) 在android.view.LayoutInflater.inflate(LayoutInflater.java:396) 在android.view.LayoutInflater.充气(LayoutInflater.java:352) 位于com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256) 位于android.app.Activity.setContentView(Activity.java:1867) 位于com.jch.latransit.MainActivity.onCreate(MainActivity.java:43) 在android.app.Activity.performCreate上(Activity.java:5008) 位于org.fest.reflect.method.Invoker.invoke(Invoker.java:112) 位于org.roblectric.util.ActivityController$1.run(ActivityController.java:116) 位于org.roblectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:256) 位于org.roblectric.util.ActivityController.create(ActivityController.java:111) 位于org.roblectric.util.ActivityController.create(ActivityController.java:123) 位于com.jch.latransit.domain.TestTimeStamp.setUp(TestTimeStamp.java:33) 位于org.junit.runners.model.FrameworkMethod$1.runReflectVeCall(FrameworkMethod.java:45) 位于org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) 位于org.junit.runners.model.FrameworkMethod.invokeeexplosive(FrameworkMethod.java:42) 位于org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27) 位于org.junit.internal.runners.statements.runafter.evaluate(runafter.java:30) 位于org.roblectric.roblectrictTestRunner$2.evaluate(roblectrictTestRunner.java:234) 位于org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263) 位于org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68) 位于org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47) 位于org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) 位于org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) 位于org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) 访问org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) 位于org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) 位于org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) 位于org.roblectric.roblectrictTestRunner$1.evaluate(roblectrictTestRunner.java:175) 位于org.junit.runners.ParentRunner.run(ParentRunner.java:300) 位于org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) 位于org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 位于org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) 位于org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) 位于org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) 位于org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) 原因:java.lang.reflect.InvocationTargetException 位于sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法) 位于sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) 在sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 位于java.lang.reflect.Constructor.newInstance(Constructor.java:526) 在android.view.LayoutInflater.$$robo$$LayoutInflater\u 1d1f\u createView(LayoutInflater.java:587) 在android.view.LayoutInflater.createView(LayoutInflater.java)中 位于org.robollectric.shadows.robolayoutfillater.onCreateView(robolayoutfillater.java:38) 位于android.view.LayoutInflater.$$robo$$LayoutInflater\u 1d1f\u onCreateView(LayoutInflater.java:660) 在android.view.LayoutInflater.onCreateView(LayoutInflater.java)中 在android.view.LayoutInflater.$$robo$$LayoutInflater\u 1d1f\u createViewFromTag(LayoutInflater.java:685) 在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java)上 在android.view.LayoutInflater.$$robo$$LayoutInflater\u 1d1f\u rInflate(LayoutInflater.java:746) 位于android.view.LayoutInflater.rInflate(LayoutInflater.java) 在android.view.LayoutInflater.$$robo$$LayoutInflater\u 1d1f\u充气(LayoutInflater.java:489) 在android.view.LayoutInflater.inflate(LayoutInflater.java)中 在android.view.LayoutInflater.$$robo$$LayoutInflater\u 1d1f\u充气(LayoutInflater.java:396) 在android.view.LayoutInflater.inflate(LayoutInflater.java)中 在android.view.LayoutInflater.$$robo$$LayoutInflater\u 1d1f\u充气(LayoutInflater.java:352) 在android.view.LayoutInflater.inflate(LayoutInflater.java)中 在com.android.internal.policy.impl.PhoneWindow.$$robo$$PhoneWindow\u 1a87\u setContentView(PhoneWindow.java:256)上 位于com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java) 在android.app.Activity.$$robo$$Activity_c57b_setContentView(Ac
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <ListView
        android:id="@+id/android:list"
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:fastScrollEnabled="true" >
    </ListView>

    <TextView
        android:id="@+id/android:empty"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mListAdapter = new ArrayAdapter<String>(this, R.layout.route_item, R.id.list_item);
    setListAdapter(mListAdapter);

    showProgDialog(this, "Loading routes...");
    new GetRoutesTask().execute("http://" + getString(R.string.la_metro_query_host)
          + getString(R.string.la_metro_route_query));
}
java.lang.StringIndexOutOfBoundsException: String index out of range: -9
android:id="@android:id/list"