Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Butterknife Fragment Injecting Views Not Working?

Can anyone explain why my View element (ListView) is null with the following code:

public class NewsFragment extends Fragment {

    @InjectView(R.id.news_listView) ListView lv;

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

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        if (lv == null) {
            UIHelper.showAlert("null?");
        }
    }
}

Am I doing something wrong or is there something wrong with the library, because I pasted the example code to my app to get it working, but it's not working here... Any help is much appreciated!

like image 768
Aerial Avatar asked Dec 14 '13 18:12

Aerial


1 Answers

Have you setup your IDE?

IDE CONFIGURATION

Some IDEs require additional configuration in order to enable annotation processing.

IntelliJ IDEA — If your project uses an external configuration (like a Maven pom.xml) then annotation processing should just work. If not, try manual configuration.

Eclipse — Set up manual configuration

Usually this means that the annotation processor didn't do its work. That might be due to misconfiguration or random problems with the IDE. In my experience, every now and then I had to clean the project and build everything again.

like image 73
Pedro Loureiro Avatar answered Nov 07 '22 03:11

Pedro Loureiro