-1

I have the following code:

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();
    }

}

Error is occuring on the line with textview.setText("Hello");.

hon2a
  • 7,006
  • 5
  • 41
  • 55
  • possible duplicate of [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) – Artjom B. Dec 08 '14 at 09:42

1 Answers1

4

You should read the document carefully :)

not:

ButterKnife.inject(getActivity(), rootView);

change to:

ButterKnife.inject(this, rootView);
Jerome
  • 1,749
  • 1
  • 14
  • 40