-1

我有以下代码:

public static class PlaceholderFragment extends Fragment {

    private static final String ARG_SECTION_NUMBER = "section_number";

    @InjectView(R.id.testTv)
    TextView textView;            

    public static PlaceholderFragment newInstance(int sectionNumber) {
        PlaceholderFragment fragment = new PlaceholderFragment();
        Bundle args = new Bundle();
        args.putInt(ARG_SECTION_NUMBER, sectionNumber);
        args.putString("product_url");
        fragment.setArguments(args);
        return fragment;
    }

    public PlaceholderFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_userprofile_myaccount, container, false);

        ButterKnife.inject(getActivity(), rootView);

        textView.setText("Hello");

        return rootView;
    }

    @Override
    public void onDetach() {
        super.onDetach();
    }

}

错误发生在与textview.setText("Hello");.

4

1 回答 1

4

你应该仔细阅读文档:)

不是:

ButterKnife.inject(getActivity(), rootView);

改成:

ButterKnife.inject(this, rootView);
于 2014-12-08T09:23:50.377 回答