錯誤內容
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;
文件渲染錯誤,打開布局文件看看有沒有錯提示,或者如果你潛入了自己的view,那麼這個對象必須有一個不少於兩個參數的構造函數才行