CountryCodePickerProject
CountryCodePickerProject copied to clipboard
Error Inflating CountryCodePicker in new version 2.3.1
I use android X in my app. So i take the latest version of CountryCodePicker to use. When i launch the fragment where is the widget, my app crash with this error : android.view.InflateException: Binary XML file line #44: Binary XML file line #44: Error inflating class com.hbb20.CountryCodePicker
Here is the stack
W/System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setVisibility(int)' on a null object reference
W/System.err: at com.hbb20.CountryCodePicker.refreshArrowViewVisibility(CountryCodePicker.java:478)
W/System.err: at com.hbb20.CountryCodePicker.applyCustomProperty(CountryCodePicker.java:309)
at com.hbb20.CountryCodePicker.init(CountryCodePicker.java:220)
at com.hbb20.CountryCodePicker.<init>(CountryCodePicker.java:156)
at java.lang.reflect.Constructor.newInstance0(Native Method)
W/System.err: at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
W/System.err: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
W/System.err: at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
W/System.err: at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at io.kamix.kamix.ui.login.KamixLoginMobileFragment.onCreateView(KamixLoginMobileFragment.java:51)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2439)
W/System.err: at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460)
at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
W/System.err: at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:802)
at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
W/System.err: at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
at androidx.fragment.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:2243)
W/System.err: at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:654)
at androidx.fragment.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:146)
at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1244)
W/System.err: at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1092)
at androidx.viewpager.widget.ViewPager.onMeasure(ViewPager.java:1622)
at android.view.View.measure(View.java:22731)
W/System.err: at androidx.constraintlayout.widget.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1572)
at android.view.View.measure(View.java:22731)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6789)
W/System.err: at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
at android.view.View.measure(View.java:22731)
W/System.err: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6789)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
W/System.err: at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
at android.view.View.measure(View.java:22731)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6789)
W/System.err: at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:22731)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6789)
W/System.err: at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
at android.view.View.measure(View.java:22731)
W/System.err: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6789)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at com.android.internal.policy.DecorView.onMeasure(DecorView.java:726)
W/System.err: at android.view.View.measure(View.java:22731)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2530)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1557)
W/System.err: at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1825)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1445)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7013)
W/System.err: at android.view.Choreographer$CallbackRecord.run(Choreographer.java:921)
at android.view.Choreographer.doCallbacks(Choreographer.java:729)
at android.view.Choreographer.doFrame(Choreographer.java:664)
W/System.err: at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:907)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err: at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6524)
at java.lang.reflect.Method.invoke(Native Method)
W/System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:451)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:888)
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: io.kamix.kamix, PID: 2863
android.view.InflateException: Binary XML file line #44: Binary XML file line #44: Error inflating class com.hbb20.CountryCodePicker
Caused by: android.view.InflateException: Binary XML file line #44: Error inflating class com.hbb20.CountryCodePicker
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at io.kamix.kamix.ui.login.KamixLoginMobileFragment.onCreateView(KamixLoginMobileFragment.java:51)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2439)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460)
at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:802)
at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
at androidx.fragment.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:2243)
at androidx.fragment.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:654)
at androidx.fragment.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:146)
at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1244)
at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1092)
at androidx.viewpager.widget.ViewPager.onMeasure(ViewPager.java:1622)
at android.view.View.measure(View.java:22731)
at androidx.constraintlayout.widget.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
at androidx.constraintlayout.widget.ConstraintLayout.onMeasure(ConstraintLayout.java:1572)
at android.view.View.measure(View.java:22731)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6789)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
at android.view.View.measure(View.java:22731)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6789)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
at android.view.View.measure(View.java:22731)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6789)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
at android.view.View.measure(View.java:22731)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6789)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
at android.view.View.measure(View.java:22731)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6789)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
E/AndroidRuntime: at com.android.internal.policy.DecorView.onMeasure(DecorView.java:726)
at android.view.View.measure(View.java:22731)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2530)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1557)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1825)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1445)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7013)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:921)
at android.view.Choreographer.doCallbacks(Choreographer.java:729)
at android.view.Choreographer.doFrame(Choreographer.java:664)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:907)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6524)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:451)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:888)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.RelativeLayout.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
at com.hbb20.CountryCodePicker.init(CountryCodePicker.java:222)
at com.hbb20.CountryCodePicker.<init>(CountryCodePicker.java:156)
... 67 more
Thanks for reporting.. I will look into this after work.. Meanwhile can you send me the XML layout you are using?
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:theme="@style/AppTheme.TransparentStatusBar"
android:background="@drawable/background_pattern_white"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.login.KamixLoginMobileFragment">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:text="@string/kamix_login_mobile_todo"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="32dp"
android:gravity="center_vertical"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
app:layout_constraintVertical_bias="0.0">
<com.hbb20.CountryCodePicker
android:id="@+id/activity_verify_phone_number_ccp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginTop="12dp"
app:ccp_textSize="12sp"
app:ccp_autoDetectCountry="true"
app:ccp_autoDetectLanguage="true"
app:ccp_autoFormatNumber="true"
app:ccp_contentColor="@color/colorBlackDisabledText"
app:ccp_countryPreference="us,ca,cm"
app:ccp_showNameCode="false" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/activity_verify_phone_number_phone_TextInputLayout"
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/kamix_login_mobile_mobile_label"
android:textColorHint="@color/colorBlackPrimaryText"
app:errorEnabled="false"
app:errorTextAppearance="@style/error_appearance"
app:hintEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/activity_verify_phone_number_phone_EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawablePadding="16dp"
android:hint="@string/kamix_login_mobile_mobile_label"
android:inputType="phone"
android:imeOptions="actionDone"
android:singleLine="true"
android:textColor="@color/colorBlackPrimaryText"
android:textColorHint="@color/colorWhiteDisabledText" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/activity_welcome_next_btn"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:layout_marginBottom="32dp"
android:layout_weight="1"
android:text="@string/kamix_login_continue"
android:textColor="@color/white"
app:cornerRadius="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/linearLayout"
app:layout_constraintVertical_bias="0.0" />
<ImageView
android:layout_width="match_parent"
android:layout_height="360dp"
android:src="@drawable/waves_background"
android:adjustViewBounds="true"
android:scaleType="fitXY"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0"
tools:ignore="VectorDrawableCompat"
android:contentDescription="@string/app_name" />
</androidx.constraintlayout.widget.ConstraintLayout>
It seems that all widgets are null, i.e. the ids of the widgets in the library do not exist.
That's weird.. I created brand new testing app and used 2.3.1 version of CCP with the attributes you specified. Somehow it worked.

I am sure you must have tried by cleaning and rebuilding project. I wonder if this can be because of gradle version?
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "io.kamix.kamix"
minSdkVersion 19
targetSdkVersion 28
versionCode 26
versionName "1.1.0.2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
multiDexKeepFile file('multidex-config.txt')
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//Lifecycle
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
//implementation "androidx.lifecycle:lifecycle-extensions:2.0.0"
//Firebase
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.google.firebase:firebase-auth:19.0.0'
//Support libraries
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.multidex:multidex:2.0.0'
//Mentions
implementation 'org.apache.commons:commons-lang3:3.4'
implementation 'com.percolate:caffeine:0.3.3'
//Widgets libraries
implementation 'com.weiwangcn.betterspinner:library-material:1.1.0'
implementation 'com.ajts.androidmads.fontutils:fontutils:1.0.2'
implementation 'com.github.davidmigloz:number-keyboard:2.0.1'
implementation 'com.poovam:pin-edittext-field:1.1.2'
implementation 'com.github.joielechong:countrycodepicker:2.4.1'
implementation 'com.hbb20:ccp:2.3.1'
//debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.0-alpha-2'
//implementation project(':ccp')
implementation 'com.googlecode.libphonenumber:libphonenumber:7.2.2'
implementation 'com.github.clans:fab:1.6.4'
implementation 'com.github.rubensousa:bottomsheetbuilder:1.6.1'
implementation 'com.github.congfandi:simpleDatePicker:Dateicker'
implementation 'com.github.yesterselga:country-picker-android:1.0'
implementation 'com.aurelhubert:ahbottomnavigation:2.2.0'
implementation 'com.weiwangcn.betterspinner:library:1.1.0'
implementation 'com.rengwuxian.materialedittext:library:2.1.4'
implementation 'com.google.android:flexbox:1.0.0'
implementation 'com.github.ganfra:material-spinner:2.0.0'
implementation 'com.jemshit:crystal-range-seekbar:1.2.0'
implementation 'xyz.danoz:recyclerviewfastscroller:0.1.3'
implementation 'com.dinuscxj:circleprogressbar:1.1.1'
implementation 'com.anttek.boundedview:library:1.0@aar'
implementation 'com.github.chrisbanes:PhotoView:2.1.2'
implementation 'com.google.android.exoplayer:exoplayer:r2.3.0'
//Emojis
implementation 'com.vanniktech:emoji:0.5.1'
implementation 'com.vanniktech:emoji-ios:0.5.1'
//Orm
implementation 'com.github.satyan:sugar:1.5'
//Permissions
implementation 'com.karumi:dexter:5.0.0'
//Device infos
implementation 'com.jaredrummler:android-device-names:1.1.8'
//Image
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.github.bumptech.glide:glide:4.3.1'
//Network
implementation 'com.squareup.retrofit2:retrofit:2.0.2'
implementation 'com.google.code.gson:gson:2.6.1'
implementation 'com.squareup.retrofit2:converter-gson:2.0.2'
implementation files('libs/ion-1.3.7.jar')
implementation files('libs/androidasync-1.3.7.jar')
implementation 'com.mindorks.android:prdownloader:0.5.0'
implementation 'com.squareup.okhttp3:okhttp:3.4.1'
//QRCode
implementation 'me.dm7.barcodescanner:zbar:1.8.4'
implementation 'com.github.kenglxn.QRGen:android:2.5.0'
//Chat library
implementation 'com.sendbird.sdk:sendbird-android-sdk:3.0.88'
//implementation files('libs/sendbird-android-sdk-3.0.88.jar')
//Test libraries
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
//Audio Recorder
implementation 'com.github.piasy:rxandroidaudio:1.5.0'
implementation 'com.github.piasy:AudioProcessor:1.5.0'
implementation 'net.the4thdimension:audio-wife:1.0.3'
//Web page parser
implementation 'org.jsoup:jsoup:1.11.2'
}
configurations.all {
resolutionStrategy {
force 'com.android.support:design:28.0.0'
force 'com.android.support:support-v4:28.0.0'
force 'com.android.support:appcompat-v7:28.0.0'
force 'com.android.support:recyclerview-v7:28.0.0'
}
}
apply plugin: 'com.google.gms.google-services'
Maybe a dependency in my gradle file can cause the issue This is my gradle file
I also tried to download the library project and add this as a dependency, but i had the same error.
I found this lib now and when I try to use it I get the same error.
Version: com.hbb20:ccp:2.3.3
Also there are these lines in traceback:
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.hbb20.CountryCodePicker"
Caused by: java.lang.NoClassDefFoundError: com.futuremind.recyclerviewfastscroll.R$layout
Update:
Fixed by:
-keep class com.hbb20.CountryCodePicker {*;}
-keep class com.futuremind.recyclerviewfastscroll.* {*;}