Android Question How solv receiver type from JavaObject

pcicom

Member
Licensed User
Longtime User
Hi

How solv receiver type from JavaObject

my code is

B4X:
    Dim scan As JavaObject
    '**************************************   
'    scan.InitializeStatic("android.device.ScanManager")
    scan.InitializeNewInstance("android.device.ScanManager",Null)
    
    Dim joOpen As JavaObject
    Dim lOpen As Boolean
    joOpen = scan.RunMethodJO("openScanner",Null)
    lOpen = joOpen.as(Boolean)

the response of compiled is

java.lang.IllegalArgumentException: Expected receiver of type android.device.ScanManager, but got java.lang.Class<android.device.ScanManager>


tanks
 

teddybear

Well-Known Member
Licensed User
Dim joOpen As JavaObject
Dim lOpen As Boolean
joOpen = scan.RunMethodJO("openScanner",Null)
lOpen = joOpen.as(Boolean)
It seems the openScanner returns a boolean, Try lOpen= scan.RunMethodJO("openScanner",Null)
 
Upvote 0

pcicom

Member
Licensed User
Longtime User
Thanks for answering.

i use the following sdk


I can already print through the SDK, doing the following

B4X:
    lPrinterReady = False
    Dim GetPrinter as JavaObject
   
    GetPrinter.InitializeNewInstance("android.device.PrinterManager",Null) 
   
    ob = GetPrinter.RunMethodJO("open",Null)  
    nPrinterReady = ob.As(Int)
    If nPrinterReady=0 Then
        cDummy = GetPrinter.RunMethodJO("setupPage",Array As Object(nPW,nPH)).As(String)
        cDummy = GetPrinter.RunMethodJO("clearPage",Null).As(String)
        ....
        Printing CODE..
        ....
    end if


According to the instructions of the SDK and the way in which I obtain data is identical to the one I use with the printer, but with the scanner it does not work, it shows me that error.

B4X:
   scan.InitializeNewInstance("android.device.ScanManager",Null)                <--   Ok no problem
    ob = scan.RunMethodJO("openScanner",Null)                                           <-- ERROR
    nPrinterReady = ob.As(Int)

    or

    scan.RunMethodJO("openScanner",Null)                                              <-- ERROR

    or

    scan.RunMethod("openScanner",Null)                                              <-- ERROR
 
Upvote 0

pcicom

Member
Licensed User
Longtime User
It seems the openScanner returns a boolean, Try lOpen= scan.RunMethodJO("openScanner",Null)

Yes I already did but it doesn't work

What the error message says is that the expected result is different from the returned type


java.lang.IllegalArgumentException: Expected receiver of type android.device.ScanManager, but got java.lang.Class<android.device.ScanManager>
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
java.lang.IllegalArgumentException:
Usually means that an argument passed to a method is of the wrong type, but I can't see why that would apply here. Can you copy and paste the whole error message from the log?
 
Upvote 0

pcicom

Member
Licensed User
Longtime User
Usually means that an argument passed to a method is of the wrong type, but I can't see why that would apply here. Can you copy and paste the whole error message from the log?

Hi, tanks for you support



ERROR 1: scan.InitializeNewInstance("android.device.ScanManager",Null)






ERROR 2: scan.InitializeStatic("android.device.ScanManager")


 
Upvote 0

aeric

Expert
Licensed User
Longtime User
B4X:
' scan.InitializeStatic("android.device.ScanManager")
scan.InitializeNewInstance("android.device.ScanManager",Null)

What happen if you use scan.InitializeStatic ?

Edit: Ops, you tried it in second image.

B4X:
Dim joOpen As JavaObject = scan.RunMethod("openScanner", Null)
 
Last edited:
Upvote 0

pcicom

Member
Licensed User
Longtime User
On SDK say


openScanner​

public boolean openScanner()
Turn on the power for the barcode reader.


Parameters:
none

Returns:
True if successful, false if failed.

Example:

ScanManager mScanManager = new ScanManager();
boolean ret = mScanManager.openScanner();
if(ret) {
//open successful
}
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…