I am trying to make my fragment work, and I cannot do everything that I am trying to do.
The error I am getting is:
java.lang.NullPointerException: attempt to call the virtual method void android.widget.TextView.setText (java.lang.CharSequence) 'to reference the null object
Here is the code:
public class FragmentOne extends Fragment {
private TextView one;
public FragmentOne() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
one = (TextView) getActivity().findViewById(R.id.one);
one.setText("kjhbguhjg");
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment1, container, false);
}
}
I donβt know why this is not working. I am testing this class only to see if the text will be changed in text form. I use the correct identifier because I checked it like 10 times, but I think the problem is that textview one is a null object. But why doesn't he find the identifier?
source
share