i'm implementing fragments in activity ,sometimes shows following error.when trying load appactivity fragment. please me rid out of error
java.lang.runtimeexception: unable start activity componentinfo{com.example.rff/com.example.rff.parent}: android.view.inflateexception: binary xml file line #68: error inflating class fragment
here xml file
<?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" > <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:id="@+id/frag_parent" > <tablelayout android:id="@+id/tablenew" android:layout_width="match_parent" android:layout_height="100dp" android:background="#fff" android:paddingtop="1dp" android:stretchcolumns="0" > <tablerow android:background="#000000" android:paddingbottom="1dp" android:paddingright="1dp" android:tag="new"> <textview android:id="@+id/newactivity" android:text="@string/newact" android:gravity="center" android:layout_marginleft="1dp" android:textcolor="#000000" android:background="#fff" android:padding="10dp" android:textsize="50sp" /> </tablerow> </tablelayout> </linearlayout> <linearlayout android:layout_width="1000dp" android:layout_height="50dp"> <button android:id="@+id/app_new" android:layout_width="420dp" android:layout_height="match_parent" android:text="apps"/> <button android:id="@+id/doc_new" android:layout_width="400dp" android:layout_height="match_parent" android:text="docs"/> </linearlayout> <fragment class="com.example.rff.appactivity" android:id="@+id/lm_fragment" android:layout_width="0dp" android:layout_height="wrap_content" /> <fragment class="com.example.rff.docactivity" android:id="@+id/doc_fragment" android:layout_width="0dp" android:layout_height="wrap_content" /> </linearlayout>
here parent fragment activity
fragmentmanager fragmentmanager = getfragmentmanager(); fragmenttransaction fragmenttransaction = fragmentmanager.begintransaction(); appactivity appactivity = new appactivity(); fragmenttransaction.replace(android.r.id.content, appactivity); fragmenttransaction.commit();
appactivity
public class appactivity extends fragment{ context context; arraylist<viewgroup> viewslist; updateappthread updatethread; view view; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view view = inflater.inflate(r.layout.app_new_layout,container, false); context = view.getcontext(); ... .... return view ; }
this best guess, since layout files , rest of code seem fine.
depending on minimum sdk declared in manifest, if have lower 11 make sure have following imports:
- in fragment class: import android.support.v4.app.fragment;
- in parent activity: import android.support.v4.app.fragmentactivity;
- make parent activity extend fragmentactivity instead of activity