Hello so I am trying to pass an array list from my activity to the fragment and this is what I did :
FirstActivity :
AdminInterface instanceForInterface;
OnCreate
//
System.out.println(results.size) ; //works fine
instanceForInterface.onDataRecieved(results); // here I am getting the exception
//
public interface AdminInterface {
void onDataRecieved(ArrayList <Result> response);
}
public void setInterface(UserFragment anInterface) {
this.instanceForInterface = anInterface;
}
Fragment
OnActivityCreated
((FirstActivity) getActivity()).setInterface(this);
@Override
public void onDataRecieved(ArrayList<Result> response) {
processData(response);
}
Exception
Attempt to invoke interface method 'void **************.onDataRecieved(java.util.ArrayList)' on a null object reference
What I think :
I am calling this line
instanceForInterface.onDataRecieved(results);
in OnCreate()
before the initialisation of
((FirstActivity) getActivity()).setInterface(this);
in OnActivityCreated()
Solution Please ??
Thank You