braintree / android-card-form

A ready-made card form layout that can be included in your Android app, making it easy to accept credit and debit cards.
MIT License
366 stars 128 forks source link

App Crashes on opening cardForm(NPE) #58

Closed initishbhatt closed 5 years ago

initishbhatt commented 5 years ago

General information

Issue description

Fatal Exception: java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.size()' on a null object reference at com.braintreepayments.cardform.view.SupportedCardTypesView.setSelected(SupportedCardTypesView.java:61) at myapplicationFragment$onViewCreated$$inlined$apply$lambda$1.onCardTypeChanged(CardInputFragment.kt:63) at com.braintreepayments.cardform.view.CardForm.onCardTypeChanged(CardForm.java:734) at com.braintreepayments.cardform.view.CardEditText.updateCardType(CardEditText.java:179) at com.braintreepayments.cardform.view.CardEditText.afterTextChanged(CardEditText.java:121) at android.widget.TextView.sendAfterTextChanged(TextView.java:7705) at android.widget.TextView$ChangeWatcher.afterTextChanged(TextView.java:9514) at android.text.SpannableStringBuilder.sendAfterTextChanged(SpannableStringBuilder.java:972) at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:516) at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:454) at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:33) at android.text.method.NumberKeyListener.onKeyDown(NumberKeyListener.java:121) at android.widget.TextView.doKeyDown(TextView.java:5813) at android.widget.TextView.onKeyDown(TextView.java:5626) at android.view.KeyEvent.dispatch(KeyEvent.java:2626) at android.view.View.dispatchKeyEvent(View.java:8416) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1496) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1496) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1496) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1496) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1496) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1496) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1496) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1496) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1496) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1496) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1496) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1496) at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1496) at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:2364) at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1709) at androidx.core.view.KeyEventDispatcher.dialogSuperDispatchKeyEventPre28(KeyEventDispatcher.java:166) at androidx.core.view.KeyEventDispatcher.dispatchKeyEvent(KeyEventDispatcher.java:89) at androidx.appcompat.app.AppCompatDialog.dispatchKeyEvent(AppCompatDialog.java:206) at androidx.appcompat.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:59) at androidx.appcompat.app.AppCompatDelegateImpl$AppCompatWindowCallback.dispatchKeyEvent(AppCompatDelegateImpl.java:2533) at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:2279) at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:4072) at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4034) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3591) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3644) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3610) at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3727) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3618) at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3784) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3591) at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3644) at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3610) at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3618) at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3591) at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5869) at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5843) at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5804) at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3387) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5290) at java.lang.reflect.Method.invoke(Method.java) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:911) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:706)

quinnjn commented 5 years ago

There is no version 2.10.0 of android-card-form. Can you double check the android-card-form version?

initishbhatt commented 5 years ago

Ahh., my bad updated the version number its 3.5.0

initishbhatt commented 5 years ago

Got the same crash on Samsung J2(2016), OS - 5.1.1 - @quinnjn

quinnjn commented 5 years ago

Following the stack trace mSupportedCardTypes is null in SupportedCardTypesView.

Have you set the supported cards types for SupportedCardTypesView? You can see how we use it in our sample activity

quinnjn commented 5 years ago

I've opened a PR to fix the NPE. Thanks for letting us know.

SupportedCardTypes expects to be pre-populated with all the card types you wish to accept via SupportedCardTypesView#setSupportedCardTypes.

SupportedCardTypesView#setSelected then loops over the supported card types and visually changes their enabled status.

You can fix it now by calling setSupportedCardTypes prior to setSelected.