Skip to content Skip to sidebar Skip to footer

NullPointerException With Using ButterKnife

I enable annotation processing like this and follow this code: public class MainFragment extends Fragment implements WeatherUpdater.AsyncResponse { @BindView(R.id.temperature_max)

Solution 1:

I think you forgot to Return your View.

public class MainFragment extends Fragment implements WeatherUpdater.AsyncResponse {

@BindView(R.id.temperature_max) TextView temperature_max;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_main, container, false);
    ButterKnife.bind(this, view);
    temperature_max.setText("NULL POINTER!");
    return view; // This need to be return.
}
}

Edit 1 :

@Bind replaces @InjectView and @InjectViews. ButterKnife.bind and ButterKnife.unbind replaces ButterKnife.inject and ButterKnife.reset respectively.

And Also Add this.

TextView temperature_max = ButterKnife.findById(view, R.id.temperature_max);

Look at this Reference Here.


Solution 2:

You should use @Bind instead of @BindView. Everything else is fine.


Post a Comment for "NullPointerException With Using ButterKnife"