After searching, finally, I find out that I should use an interface to pass a list of objects from an activity to a fragment. before that, I made my object class Perceilable to send in as an argument to fragment, but it seems that it's not a good approach because I have to initiate my fragment for the first time without setting any argument and after my list of the object is ready I can pass it. So now I want to send my list via Interface but I get this error :
java.lang.NullPointerException: Attempt to invoke interface method 'void com.x.x.Interfaces.CurrenciesSync.syncCurrencies(java.util.List)' on a null object reference
at com.x.x.DashboardActivity$1.onResponse(DashboardActivity.java:124)
here is my interface file codes:
public interface CurrenciesSync {
public void syncCurrencies(List<CurrencyModel> currencies);
}
here is the way I set currencies List in DashboardActivity to syncCurrencies method:
public class DashboardActivity extends AppCompatActivity {
CurrenciesSync currenciesSync;
currenciesSync.syncCurrencies(currencies); } And how I implement it's method :
public void syncCurrencies(List<CurrencyModel> currencies) {
// using currencies here
}