Rufio Rocco Rufio Rocco - 9 months ago 69
Android Question

Butter Knife @bind in Fragment error

I follow the instructions on the website :

error : java.lang.RuntimeException: Unable to start activity ComponentInfo. java.lang.RuntimeException: Unable to bind views for com.project.myapp.OneFragment.

I try to remove

@Bind( Button btnNext;
and run no error.

public class OneFragment extends Fragment {
@Bind( 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);
return fragment;

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

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) {
public void onAttach(Context context) {
if (context instanceof OnFragmentInteractionListener) {
mListener = (OnFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnFragmentInteractionListener");

public void onDetach() {
mListener = null;
public interface OnFragmentInteractionListener {
void onFragmentInteraction(Uri uri);


Replace this:

ButterKnife.bind(this, view);


ButterKnife.bind(getActivity(), view);