-1

This crashes when the fragment has launched. Could it be in the radio-button code?

    RadioGroup q1;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        q1 = (RadioGroup) getView().findViewById(R.id.radioGQ1);
        q1.setOnCheckedChangeListener(this);
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_exercise, container, false);

    }
    rest -> http://pastebin.com/cRptSmD4
clearlight
  • 12,255
  • 11
  • 57
  • 75
Mylo
  • 13
  • 1

2 Answers2

3

You need to inflate the views first.

View root = inflater.inflate(R.layout.fragment_exercise, container, false);
q1 = (RadioGroup) root.findViewById(R.id.radioGQ1);
q1.setOnCheckedChangeListener(this);
return root;

getView() returns null until you have returned a view hierarchy from onCreateView(), so you should not be calling getView() inside that method.

Karakuri
  • 38,365
  • 12
  • 84
  • 104
0

The Context of Fragment is getActivity, if you are not initializing any view, use getActivity(). So in your code:

Replace this:

q1 = (RadioGroup) getView().findViewById(R.id.radioGQ1);

With this code:

q1 = (RadioGroup) getActivity().findViewById(R.id.radioGQ1);
W4R10CK
  • 5,502
  • 2
  • 19
  • 30