片段不在kotlin中,但在java中的作品(相同的代码)

即时通讯试图在一个FrameLayout内运行一个片段:

来自activity.kt的代码:

... frag.arguments = bundle ft.replace(R.id.framelayout_record, frag, "feedback") // ft.addToBackStack(null) ft.commitNow() ... 

这工作:

  View root; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { root = inflater.inflate(R.layout.fragment_employee_feedback, container, false); return root; } @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { new AlertDialog.Builder(getActivity()).setMessage("Testtt").show(); } 

警报显示正确

但是使用这个:

 class TestFragment : Fragment() { internal lateinit var root: View override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? { root = inflater!!.inflate(R.layout.fragment_employee_feedback, container, false) return root } override fun onViewCreated(view: View?, savedInstanceState: Bundle?) { AlertDialog.Builder(activity).setMessage("Test Kotlin").show() } } 

没有反应,只是显示布局,但没有警报,我不能访问布局元素