My android application keeps crashing when I call the dialog containing this spinner, I'm sure my XML is ok
I tried to spot the problem by making the code as a comment and it turns that the problem is with the setAdapter line
Please if anyone can help, it will be so cool.
    CountryManager cm = new CountryManager(this);
    user = new UserAppManager(this).getUser();
    String countries = user.getCountries();
    ArrayList<Country> countriesListe = cm.getCountryByCodes(countries);
    Spinner countrieSpinner = mDialogStart.findViewById(R.id.sp_countries);
    CountriesListAdapter adapter = new CountriesListAdapter(this, R.layout.country_list_item, countriesListe);
    countrieSpinner.setAdapter(adapter);
    country = user.getDefaultCountry();
    int position = adapter.indexOf(country);
    Log.w(TAG, "countries::" + countries + "|| country::" + country + " || position::" + position);
    countrieSpinner.setSelection(position);
    countrieSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int pos, long l) {
            country = Objects.requireNonNull(adapter.getItem(pos)).getCode();
        }
        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
            country = user.getDefaultCountry();
        }
code for the adapter list
    public class CountriesListAdapter extends ArrayAdapter<Country> {
private final Context context;
//private final String[] values;
private ArrayList<Country> countries;
public CountriesListAdapter(Context context,int ressource,ArrayList<Country> countries) {
    super(context, ressource, new CountryManager(context).getAllPays());
    this.context = context;
    this.countries = countries;
}
@Override
public int getCount() {
    return countries.size();
}
@Override
public Country getItem(int i) {
    return countries.get(i);
}
public int getPosition(Country item) {
    return countries.indexOf(item);
}
@Override
public long getItemId(int i) {
    return i;
}
public int indexOf( String code) {
    for (int index = 0, count = getCount(); index < count; index++)
    {
        if (getItem(index).getCode().equals(code))  {
            return index;
        }
    }
    return -1;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View rowView = inflater.inflate(R.layout.country_list_item, parent, false);
    TextView textView = (TextView) rowView.findViewById(R.id.txtViewCountryName);
    //ImageView imageView = (ImageView) rowView.findViewById(R.id.imgViewFlag);
    String prefix = getItem(position).getPrefix();
    String code = getItem(position).getCode();
    String label = getItem(position).getLabel();
    textView.setText(" "+code);
    String buttonID = "drawable/" + code.toLowerCase();
    int resID = context.getResources().getIdentifier(buttonID, "id", context.getPackageName());
    Drawable img = context.getResources().getDrawable( resID);
    textView.setCompoundDrawablesWithIntrinsicBounds( img, null, null, null);
    return rowView;
}
@Override
public View getDropDownView(int position,  View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View rowView = inflater.inflate(R.layout.country_list_item, parent, false);
    TextView textView = (TextView) rowView.findViewById(R.id.txtViewCountryName);
    //ImageView imageView = (ImageView) rowView.findViewById(R.id.imgViewFlag);
    String prefix = getItem(position).getPrefix();
    String code = getItem(position).getCode();
    String label = getItem(position).getLabel();
    textView.setText(" "+code);
    textView.setGravity(Gravity.LEFT);
    String buttonID = "drawable/" + code.toLowerCase();
    int resID = context.getResources().getIdentifier(buttonID, "id", context.getPackageName());
    Drawable img = context.getResources().getDrawable( resID);
    textView.setCompoundDrawablesWithIntrinsicBounds( img, null, null, null);
    return rowView;
}
private String GetCountryZipCode(String ssid){
    Locale loc = new Locale("", ssid);
    return loc.getDisplayCountry().trim();
}
}
I expect to get countries for each user from SQLite
 
     
     
    