片段测试错误:android.view.InflateException:二进制XML文件行#16:二进制XML文件行#16:膨胀类

问题描述 投票:0回答:1

我正在按照以下说明尝试测试片段:https://developer.android.com/training/basics/fragments/testing

但是从测试中调用launchFragmentInContainer时出现以下崩溃。

Stacktrace:

android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class <unknown>

Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class <unknown>
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
...
at android.view.LayoutInflater.$$robo$$android_view_LayoutInflater$createView(LayoutInflater.java:647)
...
at com.myapp.poll.PollHomeFragment.onCreateView(PollHomeFragment.kt:31)
...
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 13: TypedValue{t=0x2/d=0x7f0301b1 a=-1}
at android.content.res.TypedArray.getDrawableForDensity(TypedArray.java:946)
at android.content.res.TypedArray.getDrawable(TypedArray.java:930)
at android.view.View.__constructor__(View.java:5010)
at android.view.View.<init>(View.java)
at android.widget.TextView.<init>(TextView.java)
...
at com.myapp.poll.PollHomeFragment.onCreateView(PollHomeFragment.kt:31)

这里是布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context=".poll.PollActivity">

<TextView
    android:id="@+id/tvEmail"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    tools:text="[email protected]" />

<TextView                      <!-- This is line 16 -->
    android:id="@+id/tvViewPoll"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/selectableItemBackground"
    android:gravity="center"
    android:minHeight="48dp"
    android:text="View Poll" />

<TextView
    android:id="@+id/tvCreatePoll"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/selectableItemBackground"
    android:gravity="center"
    android:minHeight="48dp"
    android:text="Create Poll" />

android android-fragments android-testing android-fragmentscenario
1个回答
0
投票
确定,根据对堆栈跟踪的有根据的猜测,我尝试删除android:background="?attr/selectableItemBackground",从而解决了此问题。
© www.soinside.com 2019 - 2024. All rights reserved.