Android Question JavaObject runmethod error

HappyDad

Member
Licensed User
Longtime User
Hi, I am just started to learn JavaObject lib, trying to use it to call some method.
The following code gives an error: java.lang.IllegalArgumentException: Expected receiver of type android.hardware.camera2.CameraManager, but got java.lang.Class<android.hardware.camera2.CameraManager>.
B4X:
    Dim bo As JavaObject
    bo.InitializeStatic("android.hardware.camera2.CameraManager")
    Dim tt() As String = bo.RunMethod("getCameraIdList", Null)
I don't have any idea on how to write code to use JavaObject.
I write the above codes following the codes in https://www.b4x.com/android/forum/threads/javaobject-library.34486/.
Please give me some advice on how to change the above code to run the method and get the return value.

But the following code does work, which uses Camera2 library to declare JavaObject. "cam2" is declared as Camera2.
B4X:
    Dim tt As List
    Dim jo As JavaObject=cam2.GetCameraCharacteristics(0)
    tt=jo.RunMethod("getKeys",Null)
 

JordiCP

Expert
Licensed User
Longtime User
This
B4X:
Sub GetCameraIds as String()   
    Dim JO As JavaObject
    Dim tt() As String = JO.InitializeContext.RunMethodJO("getSystemService", Array(JO.GetField("CAMERA_SERVICE"))).RunMethod("getCameraIdList", Null)
    return tt
End Sub
 
Upvote 0
Top