2016-04-11 23 views
5

ho seguire le istruzioni sul sito web: http://jakewharton.github.io/butterknife/lama di burro @bind per errore Frammento

errore: java.lang.RuntimeException: Impossibile avviare l'attività ComponentInfo. java.lang.RuntimeException: impossibile associare le viste a com.project.myapp.OneFragment.

Provo a rimuovere @Bind(R.id.btnNext) Button btnNext; e non eseguo errori.

public class OneFragment extends Fragment { 
    @Bind(R.id.btnNext) Button btnNext; 

    private static final String ARG_PARAM1 = "param1"; 
    private static final String ARG_PARAM2 = "param2"; 

    private String mParam1; 
    private String mParam2; 

    private OnFragmentInteractionListener mListener; 

    public OneFragment() { 
     // Required empty public constructor 
    } 
    public static OneFragment newInstance(String param1, String param2) { 
     OneFragment fragment = new OneFragment(); 
     Bundle args = new Bundle(); 
     args.putString(ARG_PARAM1, param1); 
     args.putString(ARG_PARAM2, param2); 
     fragment.setArguments(args); 
     return fragment; 
    } 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     if (getArguments() != null) { 
      mParam1 = getArguments().getString(ARG_PARAM1); 
      mParam2 = getArguments().getString(ARG_PARAM2); 
     } 
    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     View view = inflater.inflate(R.layout.fragment_one, container, false); 
     ButterKnife.bind(this, view); 

     return view; 
    } 
    public void onButtonPressed(Uri uri) { 
     if (mListener != null) { 
      mListener.onFragmentInteraction(uri); 
     } 
    } 
    @Override 
    public void onAttach(Context context) { 
     super.onAttach(context); 
     if (context instanceof OnFragmentInteractionListener) { 
      mListener = (OnFragmentInteractionListener) context; 
     } else { 
      throw new RuntimeException(context.toString() 
        + " must implement OnFragmentInteractionListener"); 
     } 
    } 

    @Override 
    public void onDetach() { 
     super.onDetach(); 
     mListener = null; 
    } 
    public interface OnFragmentInteractionListener { 
     void onFragmentInteraction(Uri uri); 
    } 
} 
+0

pubblicare il tuo layout "fragment_one". @Rufio Rocco –

+0

Usa "getActivity()" non "this" in un frammento! –

risposta

11

sostituire questo:

ButterKnife.bind(this, view); 

con

ButterKnife.bind(getActivity(), view); 
Problemi correlati