Android Question Error while trying to run Open method

AndroidMadhu

Active Member
Licensed User
Hello,
I am encountering error while trying to call open method at Razorpay.
Below is my code
B4X:
Sub Button1_Click
Dim jo As JavaObject
Dim key As String="rzp_test_xxxxxxxx"
jo.InitializeNewInstance("com.razorpay.Checkout", Null)
jo.RunMethodJO("setKeyID",Array(key))
Dim Map1,Map2 As Map
Map1.Initialize
Map2.Initialize
Dim JSONGenerator1 As JSONGenerator
Map2.put("email", "[email protected]")
Map2.put("contact", "9876543210")
JSONGenerator1.Initialize(Map2)
Dim JSONGenerator As JSONGenerator
Map1.put("name", "Lito")
Map1.put("description", "Fare")
Map1.put("currency", "INR")
Map1.put("amount", "100")
Map1.put("prefill", JSONGenerator1.ToString)
JSONGenerator.Initialize(Map1)
Log(JSONGenerator.ToString)
jo.RunMethodJO("open",Array(act,JSONGenerator))

End Sub

The below Error I am getting :
B4X:
Error occurred on line: 86 (Main)
java.lang.RuntimeException: Method: open not matched.
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:129)
at anywheresoftware.b4j.object.JavaObject.RunMethodJO(JavaObject.java:138)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:6614)
at android.view.View.performClickInternal(View.java:6587)
at android.view.View.access$3100(View.java:787)
at android.view.View$PerformClick.run(View.java:26122)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6820)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)

The below Open method from Android Studio I am trying to call. The open method is running fine at Android Studio:

B4X:
public void startPayment() {
              /*
                  You need to pass current activity in order to let Razorpay create CheckoutActivity
                */
              final Activity activity = this;

              final Checkout co = new Checkout();
              co.setKeyID("rzp_test_xxxxxxxxxx");

              try {
                      JSONObject options = new JSONObject();
                      options.put("name", "Lito");
                      options.put("description", "Fare");                     
                      options.put("currency", "INR");
                      options.put("amount", "100");

                      JSONObject preFill = new JSONObject();
                      preFill.put("email", "[email protected]");
                      preFill.put("contact", "9876543210");

                      options.put("prefill", preFill);

                      co.open(activity, options);
              } catch (Exception e) {
                      Toast.makeText(activity, "Error in payment: " + e.getMessage(), Toast.LENGTH_SHORT)
                                      .show();
                      e.printStackTrace();
              }
      }

Please advice.

Thanks
 

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
see this post

The reason will probably be that you are passing the B4X JSONGenerator object to the underlying Java method and not a java JSONObject type.
 
Upvote 0

AndroidMadhu

Active Member
Licensed User
B4X:
jo.RunMethodJO("open",Array As Object(act,JSONGenerator))

@Erel .. I am getting the same error as below :
B4X:
Error occurred on line: 89 (Main)
java.lang.RuntimeException: Method: open not matched.
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:129)
at anywheresoftware.b4j.object.JavaObject.RunMethodJO(JavaObject.java:138)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:6614)
at android.view.View.performClickInternal(View.java:6587)
at android.view.View.access$3100(View.java:787)
at android.view.View$PerformClick.run(View.java:26122)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6820)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)


Please advice

Thanks
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
That error means that JavaObject cannot find a method that matches the name and type of the parameters provided. As Andrew Digitwell points out above a B4X JSONGenerator objetc is not a Java JSONObject type. Although JSONGenerator does internally use a JSONObject it is a private internal field called 'json' and is not exposed. If you know what you are doing you could get at it with a Reflection library object otherwise you would need to instatiate and populate a JSONObject with inline Java or using a JavaObject - none of which I feel up to doing at the moment I'm afraid šŸ˜·
 
Upvote 0
Top