1
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {


        GradientDrawable drawable = new GradientDrawable();
        drawable.setShape(GradientDrawable.RECTANGLE);
        drawable.setStroke(3, Color.GREEN);

        View view = inflater.inflate(R.layout.primary, container, false);
        LinearLayout layout = (LinearLayout ) view.findViewById(R.layout.primary);
        // 1 layout.setBackground(fragmentBorder); <----
                // ^ above line causes the crash ^

        layout.setBackgroundDrawable(drawable); 
        return view; 
    }

没有编译错误,只是在我试驾的时候就崩溃了

4

1 回答 1

0
LinearLayout layout = (LinearLayout ) view.findViewById(R.layout.primary);

请将上面的行更改为

 LinearLayout layout = (LinearLayout ) view.findViewById(R.id.primary);

您的线性布局保持为空,这就是它崩溃的原因

于 2017-10-28T05:12:07.090 回答