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.

publicclassMainFragmentextendsFragmentimplementsWeatherUpdater.AsyncResponse {

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

@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Viewview= 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.

TextViewtemperature_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"