Android Payfort SDK - IllegalStateException on InitSecureConnectionActivity

372 Views Asked by At

I've been stuck with this problem for how many days. Basically, the SDK Token can now be generated, but when the program goes to the registerCallback() method, my app crashes, saying that it needs to use a Theme.AppCompat (or descendant) in the Activity.

I have set the Activity that I am using to AppCompatActivity (and applies the AppCompat theme), but it did not work. I have also set the Theme of the entire Manifest to the AppCompat theme but still it didn't work.

Here's the log:

05-24 18:47:23.636 21619-21619/com.app.turnstonepizza E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.app.turnstonepizza, PID: 21619
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.turnstonepizza/com.payfort.fort.android.sdk.activities.InitSecureConnectionActivity}:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2984)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045)
    at android.app.ActivityThread.-wrap14(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6776)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
 Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
    at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:359)
    at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:328)
    at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:289)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
    at com.payfort.fort.android.sdk.activities.InitSecureConnectionActivity.onCreate(InitSecureConnectionActivity.java:51)
    at android.app.Activity.performCreate(Activity.java:6955)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3045) 
    at android.app.ActivityThread.-wrap14(ActivityThread.java) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1642) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:154) 
    at android.app.ActivityThread.main(ActivityThread.java:6776) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)

Any help would be appreciated. Thank you.

2

There are 2 best solutions below

4
On

I think you are using custom toolbar or other custom feature.

if custom toolbar then

  <!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

 <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

Otherwise read this :

https://developer.android.com/training/material/theme.html

https://developer.android.com/guide/topics/ui/look-and-feel/themes.html

https://www.tutorialspoint.com/android/android_styles_and_themes.htm

0
On

I Just solved the problem by just removing these items from style.xml file that is basically conflicting with the Payfort SDK. That solved the problem.

<style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>


    <style name="Theme.Transparent" parent="android:Theme">
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:backgroundDimEnabled">false</item>
    </style>


    <style name="MyTheme" parent="android:Theme.Holo.Dialog">
        <item name="android:alertDialogStyle">@style/CustomAlertDialogStyle</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:textColorPrimary">#FFFFFF</item>
        <item name="android:backgroundDimEnabled">false</item>
        <item name="android:textColor">#FFFFFF</item>
        <item name="android:textStyle">normal</item>
        <item name="colorAccent">@color/colorPrimaryDark</item>
        <item name="android:textSize">12sp</item>
    </style>

    <style name="CustomAlertDialogStyle">
        <item name="android:bottomBright">@android:color/transparent</item>
        <item name="android:bottomDark">@android:color/transparent</item>
        <item name="android:bottomMedium">@android:color/transparent</item>
        <item name="android:centerBright">@android:color/transparent</item>
        <item name="android:centerDark">@android:color/transparent</item>
        <item name="android:centerMedium">@android:color/transparent</item>
        <item name="android:fullBright">@android:color/transparent</item>
        <item name="android:fullDark">@android:color/transparent</item>
        <item name="colorAccent">@color/colorPrimaryDark</item>
        <item name="android:topBright">@android:color/transparent</item>
        <item name="android:topDark">@android:color/transparent</item>
    </style>