Call findViewById()
on the rootView
you just inflated and not Activity.findViewById()
. The fragment view hierarchy is not yet a part of the activity view hierarchy and trying to find the fragment's view from the activity will return null
. Invoking a method such as getChildAt()
on null
causes the NPE.
For example, change calls like
drawView = (DrawingView)findViewById(R.id.drawing);
to
drawView = (DrawingView)rootView.findViewById(R.id.drawing);