-1

これは、フラグメントが起動したときにクラッシュします。それはラジオボタンのコードにありますか?

    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
4

2 に答える 2

3

最初にビューを膨らませる必要があります。

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

getView()からビュー階層を返すまで null を返すonCreateView()ため、そのメソッド内で呼び出してはいけませんgetView()

于 2017-01-13T01:00:39.783 に答える