Android Question JavaObject Constructor not found

Discussion in 'Android Questions' started by Brandsum, Dec 22, 2018.

Tags:

Similar threads

B4A Code Snippet Version safe notification
B4A Code Snippet Workaround the NetworkOnMainThread exception
B4A Code Snippet Change CheckBox colors
B4A Tutorial Cards list with CustomListView
B4A Code Snippet Change EditText Colors
B4A Code Snippet Add pinned shortcut
  1. Brandsum

    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:
    Code:
    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:
    Code:
    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?
     
  2. stevel05

    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))
    Code:
    Dim pathEffect As JavaObject
        
    Dim Radius As Float = 10
        pathEffect.InitializeNewInstance(
    "android.graphics.CornerPathEffect",Array(Radius))
     
    Brandsum, DonManfred and Erel like this.
  3. Brandsum

    Brandsum Well-Known Member Licensed User

    Thanks its worked!
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice