由于项目需要用到静态Fragment,碰见一奇葩问题,Error inflating class fragment,包都引用的都是对的,就是运行起来报错!
报错的代码
<fragment android:name="saiyimap.com.staticfragment.TitleFragment" android:layout_width="match_parent" android:layout_height="50dp"/> <fragment android:name="saiyimap.com.staticfragment.ContentFragment" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"/>
找到原因之后的代码
<fragment android:id="@+id/title_fragment" android:name="saiyimap.com.staticfragment.TitleFragment" android:layout_width="match_parent" android:layout_height="50dp"/> <fragment android:id="@+id/content_frament" android:name="saiyimap.com.staticfragment.ContentFragment" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"/>就是因为没有加入id,所以会出现Error inflating class fragment