gpt4 book ai didi

java - 解析 android :background ="@android:drawable/alert_dark_frame" 时 Robolectric InflateException

转载 作者:行者123 更新时间:2023-11-30 02:19:58 25 4
gpt4 key购买 nike

<LinearLayout
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="70dp"
xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- MORE BUTTONS HERE -->
<Button
android:layout_width="0dp"
android:layout_height="fill_parent"
android:text="Ok"
android:id="@+id/w_save" android:layout_weight="1"/>
<TextView
android:visibility="gone"
android:textColor="@android:color/holo_blue_light"
android:text="Trasa już ustawiona"
android:gravity="center"
android:background="@android:drawable/alert_dark_frame"
android:id="@+id/widget_alreadySet"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>

下面是实际测试代码:

    @Test
public void widgetButtonPressTest() throws Exception {
ShadowAppWidgetManager appWidgetManager = new ShadowAppWidgetManager();
int widgetId = appWidgetManager.createWidget(NewTripWidgetProvider.class, R.layout.new_trip_widget);
View view = appWidgetManager.getViewFor(widgetId);
Button u1 = (Button) view.findViewById(R.id.w_u1);
u1.performClick();

NewTripWidgetReceiver mWidgetReceiver = mock(NewTripWidgetReceiver.class);

}

当我尝试执行测试时失败并出现以下异常:

android.view.InflateException: XML file .\res\layout\new_trip_widget.xml line #-1 (sorry, not yet implemented): Error inflating class android.widget.TextView
at android.view.LayoutInflater.createView(LayoutInflater.java:620)
at org.robolectric.shadows.RoboLayoutInflater.onCreateView(RoboLayoutInflater.java:38)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at org.robolectric.shadows.ShadowAppWidgetManager.createWidgetView(ShadowAppWidgetManager.java:223)
at org.robolectric.shadows.ShadowAppWidgetManager.createWidgets(ShadowAppWidgetManager.java:205)
at org.robolectric.shadows.ShadowAppWidgetManager.createWidget(ShadowAppWidgetManager.java:189)
at pl.fragoff.gascharger.roboelectrictests.WidgetTest.widgetButtonPressTest(WidgetTest.java:45)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:236)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:158)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

我发现删除以下行可以解决问题:

android:background="@android:drawable/alert_dark_frame"

知道如何在不从 View 中删除 android:backgorund 样式的情况下解决该问题吗?如果有任何帮助,我将不胜感激。

最佳答案

我想通了(如果有人有类似的问题)。

alert_dark_frame.xml 不在我的 android sdk 文件夹中。.../android/sdk/platforms/android-xx/data/res/drawable/alert_dark_frame.xml - 它必须存在。否则它不会工作。

关于java - 解析 android :background ="@android:drawable/alert_dark_frame" 时 Robolectric InflateException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28722091/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com