Reputation: 407
I'm using ButterKnife library in my android application. It works fine in Activities. But when I use that in Fragment it give me an error while building the project. Here is my code :
package com.foxastudios.stopnosocomials.Fragments;
public class FragmentObserveeOne extends Fragment {
@BindView(R.id.text_obs_one_name) TextView obsName;
public FragmentObserveeOne() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_observee_one, container, false);
ButterKnife.bind(this,rootView);
obsName.setText("TEXT");
return rootView;
}
}
My fragments are in a separate package named Fragments. And here is the errors that I get:
Error:(8, 39) error: cannot find symbol class Fragments
Error:(13, 65) error: package Fragments does not exist
Error:(27, 59) error: package Fragments does not exist
Upvotes: 0
Views: 760
Reputation: 5149
Your issue is that the package contains a capital letter. As the Java docs describe - All packages should use lowercase letters.
Package names are written in all lower case to avoid conflict with the names of classes or interfaces.
Renaming the package fragments
should fix your issue.
Finally, please check the latest Butterknife docs to see how to use Butterknife correctly with Fragment
classes to avoid memory leaks as your code at present does not use an Unbinder
. The 'BINDING RESET' section of the docs should point you in the right direction.
Upvotes: 2