I have a fragment that implements one interface with one method. When I try to access the context in the method of this interface, the application crashes with a NullPointerException . What could be the problem?
public class SomeFragment extends Fragment implements SomeInterface { @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return super.onCreateView(inflater, container, savedInstanceState); } @Override public void update(Object data) { getActivity().runOnUiThread(new Runnable() { @Override public void run() { //do something } }); } }
updatemethod occurs before the fragment attaches to activation - andreich