Android Question JavaObject Constructor not found

Brandsum

Well-Known Member
Licensed User
Hi,

I just want to set path effect to the canvas paint object. Here is the code:
Original Java Code: mCanvas.setPathEffect(new CornerPathEffect(10));
My Code:
B4X:
Dim drawingCanvas As Canvas
drawingCanvas.Initialize(panelArtwork)

Dim pathEffect As JavaObject
pathEffect.InitializeNewInstance("android.graphics.CornerPathEffect",Array(10))  'error on this line

Dim jo As JavaObject = drawingCanvas
jo = jo.GetFieldJO("paint")
jo.RunMethod("setPathEffect",Array(pathEffect))

But on InitializeNewInstance I got this error:
B4X:
Error occurred on line: 289 (Camera)
java.lang.RuntimeException: Constructor not found.
    at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:94)
    at in.quest.main.camera._initdrawing(camera.java:1331)
    at in.quest.main.camera._takepicture(camera.java:1052)
    at in.quest.main.camera$ResumableSub_Camera_preview.resume(camera.java:935)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:733)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:352)
    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:175)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
    at anywheresoftware.b4a.keywords.Common$13.run(Common.java:1680)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6863)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
** Service (starter) Destroy (ignored)**
** Activity (camera) Pause, UserClosed = true **
** Service (imagedownloader) Destroy **

What is happening? How to initialize a new instance?
 

stevel05

Expert
Licensed User
The constructor Argument radius should be a float value, calling as 10 passes an int, change the code to:

Dim pathEffect As JavaObject
Dim Radius As Float = 10
pathEffect.InitializeNewInstance("android.graphics.CornerPathEffect",Array(Radius))
B4X:
    Dim pathEffect As JavaObject
    Dim Radius As Float = 10
    pathEffect.InitializeNewInstance("android.graphics.CornerPathEffect",Array(Radius))
 
Upvote 0

Brandsum

Well-Known Member
Licensed User
The constructor Argument radius should be a float value, calling as 10 passes an int, change the code to:

Dim pathEffect As JavaObject
Dim Radius As Float = 10
pathEffect.InitializeNewInstance("android.graphics.CornerPathEffect",Array(Radius))
B4X:
    Dim pathEffect As JavaObject
    Dim Radius As Float = 10
    pathEffect.InitializeNewInstance("android.graphics.CornerPathEffect",Array(Radius))
Thanks its worked!
 
Upvote 0
Top