为什么在Android中从一个片段移动到另一个片段时会发生强制关闭?
我试图从一个片段移动,即点击一个按钮,mycontacts extends片段移动到另一个片段friendfragment extends片段。我得到的错误类似于为什么在Android中从一个片段移动到另一个片段时会发生强制关闭?,android,android-fragments,Android,Android Fragments,我试图从一个片段移动,即点击一个按钮,mycontacts extends片段移动到另一个片段friendfragment extends片段。我得到的错误类似于找不到片段的视图。我的代码和错误日志如下。请引导我,因为我是一个碎片新手 tasks.xml文件 <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/andro
找不到片段的视图
。我的代码和错误日志如下。请引导我,因为我是一个碎片新手
tasks.xml文件
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="@+id/tasky"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment
android:id="@+id/fragment1"
android:name="com.example.taskmanager.friendfragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</FrameLayout>
friendfragment.class
public class friendfragment extends Fragment {
public friendfragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.tasks, container,
false);
return view;
}
}
tasks.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="@+id/tasky"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment
android:id="@+id/fragment1"
android:name="com.example.taskmanager.friendfragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
任务:
碎片活动:
Fragment fr = new friendfragment();
FragmentManager fm=getFragmentManager();
FragmentTransaction ft=fm.beginTransaction();
ft.replace(R.id.fragment_content, fr).commit();
04-23 15:00:21.074: E/Trace(26708): error opening trace file: No such file or directory (2)
04-23 15:00:47.933: E/FragmentManager(26708): No view found for id 0x7f040051 (com.example.taskmanager:id/fragment1) for fragment friendfragment{40e187b8 #1 id=0x7f040051}
04-23 15:00:47.933: E/FragmentManager(26708): Activity state:
04-23 15:00:47.963: E/FragmentManager(26708): Local Activity 40cd4eb8 State:
04-23 15:00:47.973: E/FragmentManager(26708): mResumed=true mStopped=false mFinished=false
04-23 15:00:47.995: E/FragmentManager(26708): mLoadersStarted=true
04-23 15:00:47.995: E/FragmentManager(26708): mChangingConfigurations=false
04-23 15:00:48.003: E/FragmentManager(26708): mCurrentConfig={1.0 310mcc260mnc en_US ldltr sw320dp w320dp h455dp 160dpi nrml port finger qwerty/v/v -nav/h s.6}
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="@+id/frame_content"
android:layout_height="match_parent"
android:orientation="vertical" >
</FrameLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativewLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<!-- Your views here -->
</RelativeLayout>
public class friendfragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_friend, container,
false);
return view;
}
}
Fragment fr = new friendfragment();
FragmentManager fm=getFragmentManager();
FragmentTransaction ft=fm.beginTransaction();
ft.replace(R.id.fragment_content, fr).commit();