2 freedom wings5 freedom_wings5 于 2016.03.06 11:56 提问

安卓,null expection,说FragmentManagerImpl什么的,求解决

先上logcat:

图片说明
图片说明

估计和viewpager有关,下面上viewpager的布局:

 <?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"

    tools:showIn="@layout/activity_main" tools:context=".MainActivity"
    android:id="@+id/drawerlayout">




        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

    <ListView
        android:id="@+id/listview"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:background="#3366cc">

    </ListView>

</android.support.v4.widget.DrawerLayout>

下面是FragmentPagerAdapter:

 public class MyFragmentPagerAdapter extends FragmentPagerAdapter
{
    List<Fragment> list;
    String[] titles;
    public Fragment getItem(int position)
    {
        return list.get(position);

    }
    public int getCount()
    {
        return list.size();
    }
    MyFragmentPagerAdapter(FragmentManager fm,List<Fragment> list,String[] titles)
    {
        super(fm);
        this.list=list;
        this.titles=titles;
    }
    public String getTitle(int position)
    {
        return titles[position];
    }

}

MainActivity中和viewpager有关的部分:

  listFragment=new ArrayList<Fragment>();
        listFragment.add(f1);
        listFragment.add(f2);
        listFragment.add(f3);
        listFragment.add(f4);
        listFragment.add(f5);
        viewPager=(ViewPager)super.findViewById(R.id.viewpager);
        fragmentPagerAdapter=new MyFragmentPagerAdapter(getSupportFragmentManager(),listFragment,new String[]{"标签1","标签2","标签3","标签4","标签5"});
       viewPager.setAdapter(fragmentPagerAdapter);
        tabLayout=(TabLayout)super.findViewById(R.id.tablayout);
        for(int i=0;i<5;i++)
        {
            tabLayout.addTab(tabLayout.newTab().setText("标签"+i));
        }
        tabLayout.setTabMode(TabLayout.MODE_FIXED);
        tabLayout.setupWithViewPager(viewPager);

求教怎么解决?

1个回答

devmiao
devmiao   Ds   Rxr 2016.03.06 23:18
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!