今天用了一下fragment,造成了路径找不到的问题,把这个问题记录下来,给遇到相同问题的朋友做个参考:
我在main.xml中加入了两个fragment 代码如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:baselineAligned="false"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="@+id/fragment1"
android:name="com.example.fragmentDemo.Fragment1"
android:layout_weight="1"
android:layout_height="match_parent"
android:layout_width="0dip"
/>
<fragment
android:id="@+id/fragment2"
android:name="com.example.fragmentDemo.Fragment2"
android:layout_weight="1"
android:layout_height="match_parent"
android:layout_width="0dip"
/>
</LinearLayout>
src的包名和类名如下图所示:
结果出现了说是
com.example.fragmentDemo.Fragment1
这个路径找不到的错误。
经过网友指点,发现原来是因为我的
fragment是导入v4包,而这个要求Activity要继承FragmentActivity。所以将MainActivity继承FragmentActivity即可。