错误内容
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.esen.aixiaobao/com.esen.aixiaobao.application.news.activity.NewsMainActivity}: android.view.InflateException: Binary XML file line #81: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2344)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2396)
at android.app.ActivityThread.access$600(ActivityThread.java:163)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1365)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5398)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #81: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:281)
at android.app.Activity.setContentView(Activity.java:1889)
at com.esen.aixiaobao.application.news.activity.NewsMainActivity.onCreate(NewsMainActivity.java:26)
Activity部分代码
public class NewsMainActivity extends FragmentActivity {
private Fragment[] fragments;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_fragment_news);
FragmentNews fragment = new FragmentNews();
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_news, fragment).commit();
fragments = new Fragment[2];
fragments[0] = getSupportFragmentManager().findFragmentById(R.id.fragment_news);
fragments[1] = getSupportFragmentManager().findFragmentById(R.id.fragment_focus);
getSupportFragmentManager().beginTransaction().
hide(fragments[1]).show(fragments[0]).commit();
}
Fragment 相关代码
public class FragmentNews extends Fragment{
private FragmentActivity activity;
private MyListView listView;
private NewsListViewAdapter adapter;
private List<News> newses;
//当前页数
private int pageNow = 0;
//判断是否加载更多
private boolean isLoading =false;
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){
View view = inflater.inflate(R.layout.fragment_news,container,false);
return view;
}
代码目的,我是想从一个activity(one)跳转到另一个activity(two)上,但是我的
activity(two)是继承FragmentActivity的。 Fragment才是主要显示页面。
public void onClick(View view) {
switch (view.getId()) {
case R.id.home_family_textview_icon_notify:
Intent intent = new Intent(getActivity(), NewsMainActivity.class);
startActivity(intent);
break;