我正在编写一个 Android 单元测试,测试一个 Fragment 启动一个包含另一个 Fragment 的 Activity。活动布局看起来像
<?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:orientation="vertical" >
<fragment
android:id="@+id/signup_finish_fragment"
class="com.example.MyFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
当我启动测试时,我在方法中得到以下异常inflater.inflate()
:
java.lang.ClassNotFoundException: android.view.include
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.view.LayoutInflater.createView(LayoutInflater.java:552)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:636)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at com.example.MyFragment.onCreateView(MyFragment.java:77)
这个异常的原因是什么,我该如何解决这个问题?我没有android.view.include
在官方文档中找到任何关于该类的提及。
UPD:这是 MyFragment 布局代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="@id/first_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
<EditText
android:id="@id/last_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName" />
<LinearLayout
android:id="@id/captcha_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent">
<ImageView
android:id="@id/captcha"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:adjustViewBounds="true"/>
<ProgressBar
android:id="@id/captcha_progress"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:indeterminate="true"
android:visibility="gone"/>
</RelativeLayout>
<ImageButton
android:id="@id/refresh_captcha"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/btn_signup_refresh"
android:scaleType="center"/>
</LinearLayout>
<EditText
android:id="@id/captcha_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<CheckBox
android:id="@id/agreement_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/btn_check"/>
<TextView
android:id="@id/agreement_link"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|left"/>
</LinearLayout>
<Button
android:id="@id/done"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/done" />
</LinearLayout>