2014-12-08 8 views
-1

를 사용하여 텍스트 뷰를 초기화하는 동안 다음과 같은 코드가 있습니다널 포인터 예외가 발생하는됩니다 Butterknife

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");와 라인에 발생하는됩니다.

+0

중복 가능성을 [I가 해결합니까 무엇 널 (null) 포인터 예외이며, 어떻게 그것?] (http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) –

답변

4

당신은 document주의 :

하지 읽어야

ButterKnife.inject(getActivity(), rootView); 

변경하려면 다음의

ButterKnife.inject(this, rootView); 
+0

고맙습니다 .. 문제 해결 .. –

+0

@@@@@@@ all – Jerome

관련 문제