Android Question problem calling a JavaObject methode

Kronberger Reinhard

Member
Licensed User
Longtime User
Hello,
i want to show on a sunmi D3 Mini device the price on the 7 digits customerdisplay.
The sunmi developer documtents show that the method showDigital(String digital) from LcdApi do this.

I have tried different things in my b4a project but always with errors.

Attched the sunmisdk.jar which i have included and copied to the \Anywhere Software\B4A\Libraries folder.
AdditionalJar.jpg


the method calling with error

Error.jpg


any idea what i have done wrong?

thanks
 

Attachments

  • sunmisdk.jar
    161.3 KB · Views: 10

Kronberger Reinhard

Member
Licensed User
Longtime User
the method which i am calling.

Sub ShowPriceSunmiD3(Price As Double)
Dim jo As JavaObject
jo.InitializeStatic("com.sunmi.printerx.api.LcdApi").RunMethod("showDigital", Array(NumberFormat2(Price, 1, 2, 2, False)))
End Sub

Including the jar

#Region Project Attributes
#ApplicationLabel: EASY_POS
#VersionCode: 40
#VersionName: Easy-Pos131224
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: landscape
#CanInstallToExternalStorage: False
#End Region
#AdditionalJar: sunmisdk

The Errormessage


Error occurred on line: 956 (Main)
java.lang.IllegalArgumentException: Expected receiver of type com.sunmi.printerx.api.LcdApi, but got java.lang.Class<com.sunmi.printerx.api.LcdApi>
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
at anywheresoftware.b4j.object.JavaObject.RunMethodJO(JavaObject.java:139)
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:157)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:205)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at kro4pro.software.easy_pos_neu.main._betraganzeigen(main.java:8949)
at kro4pro.software.easy_pos_neu.main._artikelbuttonclick(main.java:8672)
at kro4pro.software.easy_pos_neu.main._b2_click(main.java:9872)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:205)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:7506)
at android.view.View.performClickInternal(View.java:7483)
at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
at android.view.View$PerformClick.run(View.java:29345)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7935)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:942)
 
Last edited:
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
In the IDE screenshot you are calling RunMethodJO not RunMethod. That would pass an Object and not a value.
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Sub ShowPriceSunmiD3(Price As Double)
Dim jo As JavaObject
jo.InitializeStatic("com.sunmi.printerx.api.LcdApi").RunMethod("showDigital", Array(NumberFormat2(Price, 1, 2, 2, False)))
End Sub
Try this code
B4X:
    Dim jo As JavaObject
    jo.InitializeNewInstance("com.sunmi.printerx.api.LcdApi",Null).RunMethod("showDigital", Array(NumberFormat2(Price, 1, 2, 2, False)))
 
Upvote 0

Kronberger Reinhard

Member
Licensed User
Longtime User
Try this code
B4X:
    Dim jo As JavaObject
    jo.InitializeNewInstance("com.sunmi.printerx.api.LcdApi",Null).RunMethod("showDigital", Array(NumberFormat2(Price, 1, 2, 2, False)))
Get

Error occurred on line: 956 (Main)
java.lang.InstantiationException: java.lang.Class<com.sunmi.printerx.api.LcdApi> cannot be instantiated
at java.lang.Class.newInstance(Native Method)
at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:86)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:205)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at kro4pro.software.easy_pos_neu.main._showpricesunmid3(main.java:10699)
at kro4pro.software.easy_pos_neu.main._betraganzeigen(main.java:8992)
at kro4pro.software.easy_pos_neu.main._artikelbuttonclick(main.java:8672)
at kro4pro.software.easy_pos_neu.main._b1_click(main.java:9477)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:205)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:7506)
at android.view.View.performClickInternal(View.java:7483)
at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
at android.view.View$PerformClick.run(View.java:29345)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7935)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:942)
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
com.sunmi.printerx.api.LcdApi isn't a class; it's an interface. something else has to implement the showdigital() method.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You need to provide the relevant Java code snippet.

It should be something like:
B4X:
Dim PrinterSdk As JavaObject
PrinterSdk = PrinderSdk.InitializeStatic("com.sunmi.printerx.PrinterSdk").RunMethod("getInstance", Null)
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim Listener As Object = PrinterSdk.CreateEventFromUI("com.sunmi.printerx.PrinterSdk$PrintListen", "PrinterListener", Null)
PrinterSdk.RunMethod("getPrinter", Array(ctxt, Listener))


Private Sub Listen_Event(MethodName As String, Args() As Object) As Object

  Log(MethodName & ", " & Args)
  Return Null
End Sub

You will get the printer object in the event.
 
Upvote 0

teddybear

Well-Known Member
Licensed User
yes i think so because it has a link to the source in the LcdApi but it is named LcdApi.class .Unfortunately it is very hard to get good informations from sunmi.thanks
Erel has already provided you with a solution in the post#9, I have not the device, so I got the error com.sunmi.printerx.SdkException: Not found print service,
as long as you get the PrinterSdk.Printer object, you can use the lcdApi to showDigital.
This is the SDK documentation
Java code snippet looks like this:
Java:
               PrinterSdk.Printer Printer;
                try {
                    LcdApi api = Printer.lcdApi();
                    api.showDigital("1.3.5.7.9.0.1");
                } catch (SdkException e) {
                    e.printStackTrace();
                }
 
Last edited:
Upvote 0

Kronberger Reinhard

Member
Licensed User
Longtime User
Error occurred on line: 963 (Main)
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
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:157)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:205)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at kro4pro.software.easy_pos_neu.main._showpricesunmid3(main.java:10699)
at kro4pro.software.easy_pos_neu.main._betraganzeigen(main.java:8992)
at kro4pro.software.easy_pos_neu.main._artikelbuttonclick(main.java:8672)
at kro4pro.software.easy_pos_neu.main._b2_click(main.java:9873)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:205)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:7506)
at android.view.View.performClickInternal(View.java:7483)
at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
at android.view.View$PerformClick.run(View.java:29345)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7935)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:942)
Caused by: com.sunmi.printerx.SdkException: Not found print service
at com.sunmi.printerx.PrinterSdk.connectService(PrinterSdk.java:23)
at com.sunmi.printerx.PrinterSdk.getPrinter(PrinterSdk.java:8)
... 35 more
You need to provide the relevant Java code snippet.

It should be something like:
B4X:
Dim PrinterSdk As JavaObject
PrinterSdk = PrinderSdk.InitializeStatic("com.sunmi.printerx.PrinterSdk").RunMethod("getInstance", Null)
Dim ctxt As JavaObject
ctxt.InitializeContext
Dim Listener As Object = PrinterSdk.CreateEventFromUI("com.sunmi.printerx.PrinterSdk$PrintListen", "PrinterListener", Null)
PrinterSdk.RunMethod("getPrinter", Array(ctxt, Listener))


Private Sub Listen_Event(MethodName As String, Args() As Object) As Object

  Log(MethodName & ", " & Args)
  Return Null
End Sub

You will get the printer object in the event.
get this

Error occurred on line: 963 (Main)
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
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:157)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:205)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at kro4pro.software.easy_pos_neu.main._showpricesunmid3(main.java:10699)
at kro4pro.software.easy_pos_neu.main._betraganzeigen(main.java:8992)
at kro4pro.software.easy_pos_neu.main._artikelbuttonclick(main.java:8672)
at kro4pro.software.easy_pos_neu.main._b2_click(main.java:9873)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:205)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:7506)
at android.view.View.performClickInternal(View.java:7483)
at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
at android.view.View$PerformClick.run(View.java:29345)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7935)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:942)
Caused by: com.sunmi.printerx.SdkException: Not found print service
at com.sunmi.printerx.PrinterSdk.connectService(PrinterSdk.java:23)
at com.sunmi.printerx.PrinterSdk.getPrinter(PrinterSdk.java:8)
... 35 more
 
Upvote 0
Top