0

We are getting following error in account kit.
It would be very helpful if someone can tell its cause and how to fix it.

java.lang.RuntimeException: 
  at android.app.ActivityThread.performResumeActivity (ActivityThread.java:4155)
  at android.app.ActivityThread.handleResumeActivity (ActivityThread.java:4246)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3360)
  at android.app.ActivityThread.access$1100 (ActivityThread.java:221)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1794)
  at android.os.Handler.dispatchMessage (Handler.java:102)
  at android.os.Looper.loop (Looper.java:158)
  at android.app.ActivityThread.main (ActivityThread.java:7225)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1230)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1120)


Caused by: java.lang.ArrayIndexOutOfBoundsException: 
  at com.facebook.accountkit.ui.PhoneCountryCodeAdapter.getItem (PhoneCountryCodeAdapter.java:253)
  at com.facebook.accountkit.ui.PhoneContentController$TopFragment.setPhoneNumberText (PhoneContentController.java:435)
  at com.facebook.accountkit.ui.PhoneContentController$TopFragment.onViewReadyWithState (PhoneContentController.java:362)
  at com.facebook.accountkit.ui.ViewStateFragment.onActivityCreated (ViewStateFragment.java:66)
  at com.facebook.accountkit.ui.PhoneContentController$TopFragment.onActivityCreated (PhoneContentController.java:201)
  at android.app.Fragment.performActivityCreated (Fragment.java:2289)
  at android.app.FragmentManagerImpl.moveToState (FragmentManager.java:1007)
  at android.app.FragmentManagerImpl.moveToState (FragmentManager.java:1163)
  at android.app.BackStackRecord.run (BackStackRecord.java:793)
  at android.app.FragmentManagerImpl.execPendingActions (FragmentManager.java:1552)
  at android.app.FragmentController.execPendingActions (FragmentController.java:325)
  at android.app.Activity.performResume (Activity.java:7014)
  at android.app.ActivityThread.performResumeActivity (ActivityThread.java:4144)

So the line Caused by: java.lang.ArrayIndexOutOfBoundsException: at com.facebook.accountkit.ui.PhoneCountryCodeAdapter.getItem is caused due to piece of code written in the facebook library? Or it is something we can control and somehow change in through using the configuration files etc?

We are just using the https://developers.facebook.com/docs/accountkit/android in our app. It is working fine many devices, but some devices are getting above error.

Following the code for onCreate in the activity which is calling accountkit. And we are not using onResume.

SkinManager uiManager = new SkinManager(
               SkinManager.Skin.CONTEMPORARY,
               getResources().getColor(R.color.colorPrimary),
               R.drawable.login_bg2,
               SkinManager.Tint.WHITE,
               0.55D);

       intent = new Intent(this, AccountKitActivity.class);

       AccountKitConfiguration.AccountKitConfigurationBuilder configurationBuilder =
               new AccountKitConfiguration.AccountKitConfigurationBuilder(
                       LoginType.PHONE,
                       AccountKitActivity.ResponseType.TOKEN); // or .ResponseType.TOKEN

       configurationBuilder.setSMSWhitelist(new String[]{"PK"});
       configurationBuilder.setUIManager(uiManager);
       intent.putExtra(
               AccountKitActivity.ACCOUNT_KIT_ACTIVITY_CONFIGURATION,
               configurationBuilder.build());

Response Starting to get the response.

startActivityForResult(intent, APP_REQUEST_CODE);

And here we are processing the response

    @Override
        protected void onActivityResult(
                final int requestCode,
                final int resultCode,
                final Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            if (requestCode == APP_REQUEST_CODE) {
                btnContinue.setEnabled(true);
                // confirm that this response matches your request
                final AccountKitLoginResult loginResult = data.getParcelableExtra(AccountKitLoginResult.RESULT_KEY);
                if (loginResult.getError() != null) {
                } else if (loginResult.wasCancelled()) {
                } else {
                    progressDialog.show();
                    if(loginResult.getAccessToken()!=null){
                        fbAccessToken = loginResult.getAccessToken().getToken();
                    }

                    AccountKit.getCurrentAccount(new AccountKitCallback<Account>() {
                        @Override
                        public void onSuccess(Account account) {
                            PhoneNumber phoneNumber = account.getPhoneNumber();
                            phoneNumberString = phoneNumber.getPhoneNumber();
 // some bla bla to call our APIs to save the response
}
                        @Override
                        public void onError(AccountKitError accountKitError) {
                            Log.e(TAG, "onError");
                            progressDialog.hide();
                            Toast.makeText(SignInActivity.this, accountKitError.getUserFacingMessage(), Toast.LENGTH_SHORT).show();
                        }
                    });

                }
            }
        }
hhsadiq
  • 2,871
  • 1
  • 25
  • 39
  • Just from seeing the error message: You are accessing an element that is out of bounds of an array. – Ben Mar 01 '18 at 11:11
  • 1
    If you want a bit more help it would be useful to provide [Minimal, Complete and Verifiable example](https://stackoverflow.com/help/mcve) of your problem – Ben Mar 01 '18 at 11:12
  • Sure, will add more details to the question. – hhsadiq Mar 01 '18 at 11:13
  • updated the question and added few more details. Actually looks like this error is caused into facebook account kit code, so not understanding what else can I provide? Can you guys tell what more should I share? – hhsadiq Mar 01 '18 at 11:18
  • Considering that the last line of the stack trace references the resuming of an activity, you may want to show the code for when you resume it. – Federico klez Culloca Mar 01 '18 at 11:19
  • Somewhere your code throws an exception. This somewhere happens in your app. There you are somehow accessing something. We can not help you if you can not provide you with the `somewhere` the `somehow` and the `something`. – Ben Mar 01 '18 at 11:19
  • Add your `Activity` please. – Aditya Mar 01 '18 at 11:20
  • ok, updating the question shortly. Sorry for being naive, it is my first question on android and I am newbie. – hhsadiq Mar 01 '18 at 11:26
  • Ok, Updated the code where we are calling account kit. Removed few lines where were calling our APIs. – hhsadiq Mar 01 '18 at 11:37
  • @Ben so basically this error is not a problem of accountkit library? And is caused by our code..right? So on first stage it is best to know who is responsible for this crash. Facebook accountkit or our code? – hhsadiq Mar 01 '18 at 11:38
  • @hhsadiq what is more likely? That your code is broken or that a library used without issues by thousands of developers is broken? I'm not saying it's impossible, but if this is what happened you'd better open a bug against facebook than ask here. – Federico klez Culloca Mar 01 '18 at 11:42
  • @FedericoklezCulloca 100% agree with you. Actually, our Android engineer was saying that this error is caused by the accountkit and not his code, so I wanted to get a second opinion from the community. I am FullStack web engineer, and leading the ios, android, web team. My personal android skills are very weak and I rely upon people like you to get second opinion where I am doubtful. But again, thanks for helping. I am assuming that this issue is 100% caused by our code and not facebook account kit. – hhsadiq Mar 01 '18 at 12:17

2 Answers2

0

Your must call

configurationBuilder.setDefaultCountryCode("PH");

I was also troubled by this problem for a long time.

0

Here is my final code.

public class AccountKitLoginManager {
public final static int APP_REQUEST_CODE = 99;
public static void login(Activity activity){
    final Intent intent = new Intent(activity, AccountKitActivity.class);
    AccountKitConfiguration.AccountKitConfigurationBuilder configurationBuilder =
            new AccountKitConfiguration.AccountKitConfigurationBuilder(
                    LoginType.PHONE,
                    AccountKitActivity.ResponseType.CODE).setSMSWhitelist(new String[]{"MM"}); // or .ResponseType.TOKEN
    intent.putExtra(
            AccountKitActivity.ACCOUNT_KIT_ACTIVITY_CONFIGURATION,
            configurationBuilder.build());
    activity.startActivityForResult(intent, APP_REQUEST_CODE);
   }
}

First error is same to you.Couse of this code String[]{"MM , CN"}.So I remove CN.My program is fine.

H Zan
  • 359
  • 1
  • 4
  • 16