mukeshsolanki / country-picker-android

A simple library that displays a beautiful list of all the countries allowing the user to pick the country he wishes and provide details like country code, iso code name,currency and flag.
MIT License
322 stars 135 forks source link

App Crashes when try to use either showDialog() or showBottomSheet() methods. #107

Open haps87 opened 2 years ago

haps87 commented 2 years ago
Fatal Exception: java.lang.NoSuchFieldError
No static field country_flag of type I in class Lcom/mukesh/countrypicker/R$id; or its superclasses (declaration of 'com.mukesh.countrypicker.R$id' appears in /data/app/~~LBxrtR-zJZNjlGwTOmALag==/com.xyz-q5WhD_2SqWYbQIjrO3uc2g==/base.apk)

com.mukesh.countrypicker.CountriesAdapter$ViewHolder.<init> (CountriesAdapter.java:75)
com.mukesh.countrypicker.CountriesAdapter.onCreateViewHolder (CountriesAdapter.java:43)
com.mukesh.countrypicker.CountriesAdapter.onCreateViewHolder (CountriesAdapter.java:18)
androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder (RecyclerView.java:7078)

I had used the below version of the library. implementation 'com.github.mukeshsolanki:country-picker-android:2.0.4'

Here is my applied code.

// Global variable
private CountryPicker countryPicker;
// OnViewCreated
countryPicker = new CountryPicker
                .Builder()
                .with(getContext())
                .listener(country -> {
                    countryCode = country.getDialCode();
                    imgCountry.setImageResource(country.getFlag());
                    Log.e("cSelection-Select", "" + countryCode + " / flag=" + country.getCode());
                })
                .build();
 // On Image Click where app crashes.
 countryPicker.showBottomSheet(activity);
haps87 commented 2 years ago

And the funny part is within OnViewCreated method, the below code works.

final Country userCountryInfo = countryPicker.getCountryFromSIM();
countryCode = userCountryInfo.getDialCode();
imgCountry.setImageResource(userCountryInfo.getFlag());
if (BuildConfig.DEBUG)
    Log.e("cSelection-Create", "" + countryCode + " / flag=" + userCountryInfo.getFlag());
BharathKmalviya commented 8 months ago

And the funny part is within OnViewCreated method, the below code works.

final Country userCountryInfo = countryPicker.getCountryFromSIM();
countryCode = userCountryInfo.getDialCode();
imgCountry.setImageResource(userCountryInfo.getFlag());
if (BuildConfig.DEBUG)
    Log.e("cSelection-Create", "" + countryCode + " / flag=" + userCountryInfo.getFlag());

I'm using this in activity and it's crashing!!

any update or solution for this?