我在活动中实现片段,有时它会显示以下错误。当我尝试加载appactivity片段时。请帮我摆脱这个错误
Java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.rff/com.example.rff.Parent}:
android.view.InflateException: Binary XML file line #68: Error inflating class fragment
这是我的xml文件
<?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>
这是我的父片段活动
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
AppActivity appActivity = new AppActivity();
fragmentTransaction.replace(android.R.id.content, appActivity);
fragmentTransaction.commit();
活跃
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 ;
}
1条答案
按热度按时间q0qdq0h21#
这是我最好的猜测,因为您的布局文件和其余的代码似乎很好。
根据清单中声明的最小sdk,如果低于11,请确保具有以下导入:
在fragment类中:import android.support.v4.app.fragment;
在父活动中:导入android.support.v4.app.fragmentactivity;
使父活动扩展fragmentactivity而不是activity