payu-intrepos / Android-SDK

PayU Android SDK
14 stars 8 forks source link

PayUBiz i #31

Closed ghost closed 4 years ago

ghost commented 8 years ago

During testing the test android application, whenever we continue to pay via PayuBiz. Android application suddenly crashes: following is the error log:

09-12 04:23:10.299 25470-25470/com.payu.testapp W/System.err: java.lang.IllegalStateException: Fragment null must be a public static class to be properly recreated from instance state. 09-12 04:23:10.299 25470-25470/com.payu.testapp W/System.err: at android.support.v4.app.BackStackRecord.doAddOp(BackStackRecord.java:435) 09-12 04:23:10.299 25470-25470/com.payu.testapp W/System.err: at android.support.v4.app.BackStackRecord.add(BackStackRecord.java:420) 09-12 04:23:10.299 25470-25470/com.payu.testapp W/System.err: at com.payu.payuui.PaymentsActivity.onCreate(PaymentsActivity.java:166) 09-12 04:23:10.299 25470-25470/com.payu.testapp W/System.err: at android.app.Activity.performCreate(Activity.java:5231) 09-12 04:23:10.299 25470-25470/com.payu.testapp W/System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 09-12 04:23:10.299 25470-25470/com.payu.testapp W/System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) 09-12 04:23:10.299 25470-25470/com.payu.testapp W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 09-12 04:23:10.299 25470-25470/com.payu.testapp W/System.err: at android.app.ActivityThread.access$800(ActivityThread.java:135) 09-12 04:23:10.299 25470-25470/com.payu.testapp W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 09-12 04:23:10.299 25470-25470/com.payu.testapp W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102) 09-12 04:23:10.299 25470-25470/com.payu.testapp W/System.err: at android.os.Looper.loop(Looper.java:136) 09-12 04:23:10.299 25470-25470/com.payu.testapp W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5017) 09-12 04:23:10.299 25470-25470/com.payu.testapp W/System.err: at java.lang.reflect.Method.invokeNative(Native Method) 09-12 04:23:10.299 25470-25470/com.payu.testapp W/System.err: at java.lang.reflect.Method.invoke(Method.java:515) 09-12 04:23:10.299 25470-25470/com.payu.testapp W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 09-12 04:23:10.299 25470-25470/com.payu.testapp W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 09-12 04:23:10.299 25470-25470/com.payu.testapp W/System.err: at dalvik.system.NativeStart.main(Native Method)

09-12 04:23:14.439 25470-25470/com.payu.testapp E/AndroidRuntime: FATAL EXCEPTION: main Process: com.payu.testapp, PID: 25470 java.lang.NullPointerException at com.payu.custombrowser.Bank.onPageFinishWebclient(Bank.java:694) at com.payu.custombrowser.PayUWebViewClient.onPageFinished(PayUWebViewClient.java:73) at com.android.webview.chromium.WebViewContentsClientAdapter.onPageFinished(WebViewContentsClientAdapter.java:449) at com.android.org.chromium.android_webview.AwContentsClient$AwWebContentsObserver$1.run(AwContentsClient.java:73) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5017) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(Native Method)

Kindly look into the error

junaidstalkbylove commented 8 years ago

Shubham, Please create a inner Fragment class inside PaymentsActivity class and extends that fragment with Bank.class. Replace all method as mentioned in the example. It will work.

public static class MyBank extends Bank{

    @Override
    public void registerBroadcast(BroadcastReceiver broadcastReceiver, IntentFilter filter) {
        mReceiver = broadcastReceiver;
        getActivity().registerReceiver(broadcastReceiver, filter);
    }

    @Override
    public void unregisterBroadcast(BroadcastReceiver broadcastReceiver) {
        if (mReceiver != null) {
            getActivity().unregisterReceiver(mReceiver);
            mReceiver = null;
        }
    }

    @Override
    public void onHelpUnavailable() {
        getActivity().findViewById(R.id.parent).setVisibility(View.GONE);
        getActivity().findViewById(R.id.trans_overlay).setVisibility(View.GONE);
    }

    @Override
    public void onBankError() {
        getActivity().findViewById(R.id.parent).setVisibility(View.GONE);
        getActivity().findViewById(R.id.trans_overlay).setVisibility(View.GONE);
    }

    @Override
    public void onHelpAvailable() {
        getActivity().findViewById(R.id.parent).setVisibility(View.VISIBLE);
    }
}

make receiver as static. Thanks, Junaid

kathanshah commented 7 years ago

Hi, I have created class "public static class MyBank extends Bank{...}" inside PaymentsActivity and done changes in code above in PaymentsActivity Class.forName("com.payu.custombrowser.Bank"); final MyBank bank = new MyBank() {...}

have i done right ? still it is giving me error ! please help

I have attached files and error code bellow. please help urgently.

PaymentsActivity.zip

D/FA: Logging event (FE): _e, Bundle[{_o=auto, _et=7649, _sc=PayUNetBankingActivity, _si=9078936444052808821}] V/FA: Using measurement service V/FA: Connection attempt already in progress V/FA: onActivityCreated I/WebViewFactory: Loading com.google.android.webview version 54.0.2840.85 (code 284008500) I/art: Rejecting re-init on previously-failed class java.lang.Class I/art: Rejecting re-init on previously-failed class java.lang.Class I/art: Rejecting re-init on previously-failed class java.lang.Class I/art: Rejecting re-init on previously-failed class java.lang.Class I/cr_LibraryLoader: Time to load native libraries: 4 ms (timestamps 4879-4883) I/cr_LibraryLoader: Expected native library version number "54.0.2840.85", actual native library version number "54.0.2840.85" I/cr_LibraryLoader: Expected native library version number "54.0.2840.85", actual native library version number "54.0.2840.85" I/chromium: [INFO:library_loader_hooks.cc(151)] Chromium logging enabled: level = 0, default verbosity = 0 I/cr_BrowserStartup: Initializing chromium process, singleProcess=true W/System.err: java.lang.IllegalStateException: Fragment null must be a public static class to be properly recreated from instance state. W/System.err: at android.support.v4.app.BackStackRecord.doAddOp(BackStackRecord.java:435) W/System.err: at android.support.v4.app.BackStackRecord.add(BackStackRecord.java:420) W/System.err: at com.payu.payuui.PaymentsActivity.onCreate(PaymentsActivity.java:166) W/System.err: at android.app.Activity.performCreate(Activity.java:6259) W/System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130) W/System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379) W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490) W/System.err: at android.app.ActivityThread.-wrap11(ActivityThread.java) W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354) W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102) W/System.err: at android.os.Looper.loop(Looper.java:148) W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5443) W/System.err: at java.lang.reflect.Method.invoke(Native Method) W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) I/cr_Ime: ImeThread is enabled. W/cr_media: Requires BLUETOOTH permission D/FA: Connected to remote service V/FA: Processing queued up service tasks: 2 E/libEGL: validate_display:255 error 3008 (EGL_BAD_DISPLAY) V/FA: Activity resumed, time: 257615170 W/VideoCapabilities: Unrecognized profile 2130706433 for video/avc W/Utils: could not parse long range '367-367 ' W/VideoCapabilities: Unrecognized profile/level 0/3 for video/mpeg2 D/OpenGLRenderer: endAllActiveAnimators on 0xb7b5c610 (RippleDrawable) with handle 0xb7a99230 I/VideoCapabilities: Unsupported profile 4 for video/mp4v-es W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 14252 I/chromium: [INFO:CONSOLE(5)] "The value "device-width;" for key "width" is invalid, and has been ignored.", source: https://secure.payu.in/_payment (5) I/chromium: [INFO:CONSOLE(5)] "The value "1.0;" for key "initial-scale" was truncated to its numeric prefix.", source: https://secure.payu.in/_payment (5) I/chromium: [INFO:CONSOLE(5)] "The value "1.0;" for key "maximum-scale" was truncated to its numeric prefix.", source: https://secure.payu.in/_payment (5) I/chromium: [INFO:CONSOLE(5)] "The value "0;" for key "user-scalable" was truncated to its numeric prefix.", source: https://secure.payu.in/_payment (5) I/chromium: [INFO:CONSOLE(5)] "Error parsing a meta element's content: ';' is not a valid key-value pair separator. Please use ',' instead.", source: https://secure.payu.in/_payment (5) E/chromium: [ERROR:interface_registry.cc(99)] Failed to locate a binder for interface: autofill::mojom::AutofillDriver D/AndroidRuntime: Shutting down VM E/UncaughtException: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.app.Activity.findViewById(int)' on a null object reference at com.payu.custombrowser.Bank.onPageFinishWebclient(Bank.java:694) at com.payu.custombrowser.PayUWebViewClient.onPageFinished(PayUWebViewClient.java:73) at com.android.webview.chromium.WebViewContentsClientAdapter.onPageFinished(WebViewContentsClientAdapter.java:531) at org.chromium.android_webview.AwContentsClientCallbackHelper$MyHandler.handleMessage(AwContentsClientCallbackHelper.java:188) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5443) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) D/FA: Logging event (FE): _ae, Bundle[{_o=crash, _sc=PaymentActivity, _si=9078936444052808819, timestamp=1480494916596, fatal=1}] E/AndroidRuntime: FATAL EXCEPTION: main Process: com.cattechsol.skillhome, PID: 14252 java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.app.Activity.findViewById(int)' on a null object reference at com.payu.custombrowser.Bank.onPageFinishWebclient(Bank.java:694) at com.payu.custombrowser.PayUWebViewClient.onPageFinished(PayUWebViewClient.java:73) at com.android.webview.chromium.WebViewContentsClientAdapter.onPageFinished(WebViewContentsClientAdapter.java:531) at org.chromium.android_webview.AwContentsClientCallbackHelper$MyHandler.handleMessage(AwContentsClientCallbackHelper.java:188) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5443) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) Application terminated.

rickmrobin commented 7 years ago

I am also getting same error. Please Help

Fragment null must be a public static class to be properly recreated from instance state.

11-30 15:16:38.350 16992-16992/br.towness.ndrawer W/System.err: java.lang.IllegalStateException: Fragment null must be a public static class to be properly recreated from instance state. 11-30 15:16:38.351 16992-16992/br.towness.ndrawer W/System.err: at android.support.v4.app.BackStackRecord.doAddOp(BackStackRecord.java:435) 11-30 15:16:38.351 16992-16992/br.towness.ndrawer W/System.err: at android.support.v4.app.BackStackRecord.add(BackStackRecord.java:420) 11-30 15:16:38.351 16992-16992/br.towness.ndrawer W/System.err: at com.payu.payuui.PaymentsActivity.onCreate(PaymentsActivity.java:166)

rickmrobin commented 7 years ago

This problem is happening with old PayU sdk

I got new sdk version from PayU tech team. Try this

https://github.com/payu-intrepos/Android-SDK-Sample-App/releases/tag/s4.4c6.1.1m1.0.4

rahul-rahul1 commented 5 years ago

I am Facing this issue . AndroidRuntime: FATAL EXCEPTION: main Process: com.signity.bamboofoodz, PID: 28715 java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.app.Activity.findViewById(int)' on a null object reference at com.payu.custombrowser.Bank.onPageFinishWebclient(Bank.java:694) at com.payu.custombrowser.PayUWebViewClient.onPageFinished(PayUWebViewClient.java:73) at com.android.webview.chromium.WebViewContentsClientAdapter.onPageFinished(WebViewContentsClientAdapter.java:196) at org.chromium.android_webview.AwContentsClientCallbackHelper$MyHandler.handleMessage(AwContentsClientCallbackHelper.java:70) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6494) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

rahul-rahul1 commented 5 years ago

Working Code: update the CustomBrowser-release then Working fine. /* try { Class.forName("com.payu.custombrowser.Bank"); final Bank bank = new Bank() { @Override public void registerBroadcast(BroadcastReceiver broadcastReceiver, IntentFilter filter) { mReceiver = broadcastReceiver; registerReceiver(broadcastReceiver, filter); }

            @Override
            public void unregisterBroadcast(BroadcastReceiver broadcastReceiver) {
                if(mReceiver != null){
                    unregisterReceiver(mReceiver);
                    mReceiver = null;
                }
            }

            @Override
            public void onHelpUnavailable() {
                findViewById(R.id.parent).setVisibility(View.GONE);
                findViewById(R.id.trans_overlay).setVisibility(View.GONE);
            }

            @Override
            public void onBankError() {
                findViewById(R.id.parent).setVisibility(View.GONE);
                findViewById(R.id.trans_overlay).setVisibility(View.GONE);
            }

            @Override
            public void onHelpAvailable() {
                findViewById(R.id.parent).setVisibility(View.VISIBLE);
            }
        };*/
      /*  Bundle args = new Bundle();
        args.putInt(Bank.WEBVIEW, R.id.webview);
        args.putInt(Bank.TRANS_LAYOUT, R.id.trans_overlay);
        args.putInt(Bank.MAIN_LAYOUT, R.id.r_layout);
        args.putBoolean(Bank.VIEWPORTWIDE, viewPortWide);

        args.putString(Bank.TXN_ID, txnId == null ? String.valueOf(System.currentTimeMillis()) : txnId);
        args.putString(Bank.MERCHANT_KEY, null != merchantKey ? merchantKey : "could not find");
        PayUSdkDetails payUSdkDetails = new PayUSdkDetails();
        args.putString(Bank.SDK_DETAILS, payUSdkDetails.getSdkVersionName());
        if(getIntent().getExtras().containsKey("showCustom")) {
            args.putBoolean(Bank.SHOW_CUSTOMROWSER, getIntent().getBooleanExtra("showCustom", false));
        }
        args.putBoolean(Bank.SHOW_CUSTOMROWSER, true);
        bank.setArguments(args);*/
    //  findViewById(R.id.parent).bringToFront();
  /*      try {
            getSupportFragmentManager().beginTransaction().setCustomAnimations(R.anim.fade_in, R.anim.cb_face_out).add(R.id.parent, bank).commit();
        }catch(Exception e)
        {
            e.printStackTrace();
            finish();
        }
        mWebView.setWebChromeClient(new PayUWebChromeClient(bank));

        mWebView.setWebViewClient(new PayUWebViewClient(bank){
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                Log.e("Should overriding", url);

                if (url.contains("payUMoneyReturnURL?") && url.contains("status")) {
                    String payment_request_id_value = null;
                    String payment_id_value = null;
                    String status_value = null;
                    try {
                        String[] separated = url.split("payUMoneyReturnURL?");
                        separated[1] = separated[1].trim().substring(1, separated[1].trim().length());

                        String[] separated1 = separated[1].split("&");
                        String payment_request_id = separated1[0];

                        String[] payment_request = payment_request_id.trim().split("=");
                        payment_request_id_value = payment_request[1];

                        String payment_id = separated1[1];
                        String[] payment = payment_id.trim().split("=");
                        payment_id_value = payment[1];

                        String status = separated1[2];
                        String[] aStatus = status.trim().split("=");
                        status_value = aStatus[1];

                        if (status_value.equalsIgnoreCase("success")) {
                            Intent intent = new Intent();
                            intent.putExtra("payment_request_id", payment_request_id_value);
                            intent.putExtra("payment_id", payment_id_value);
                            setResult(2, intent);
                            finish();
                        } else if (status_value.equalsIgnoreCase("error")) {
                            Intent intent = new Intent();
                            setResult(3, intent);
                            finish();
                        }
                        else {
                            Intent intent = new Intent();
                            setResult(3, intent);
                            finish();
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        Intent intent = new Intent();
                        setResult(3, intent);
                        finish();
                    }

                }
                return true;
            }

        });

*/

    mWebView.setWebChromeClient(new WebChromeClient());
    mWebView.setWebViewClient(new WebViewClient());
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setDomStorageEnabled(true);
    mWebView.postUrl(url, uri.getBytes());