改为fragmentManager = getFragmentManager();试试
getFragmentManager()是获取Android.app.FragmentManager的,getSupportFragmentManager()是获取 android.support.v4.app.FragmentManager的,你看看你是属于哪一种fragmentmanager

解决方案 »

  1.   


    谢谢,getFragmentManager() 和 getSupportFragmentManager()两种都试了,还是一样的结果
      

  2.   

    贴上activity和Fragment的配置文件activity_time_tracker.xml<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.example.timetracker.TimeTrackerActivity"
        tools:ignore="MergeRootFrame" />frame_time_tracker.xml<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/fragment_tracker" 
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:baselineAligned="false"
        tools:context="com.example.timetracker.TimeTrackerActivity$TimeTrackerFragment" ></LinearLayout>
      

  3.   

    给Fragment加个tag,查找的时候用findFragmentByTag
      

  4.   

    搞定了,结贴原因是xml里面的fragment_tracker这个ID并不是一个Fragment,而是一个Layout