Android Question Error when compiling B4A project with inline Java Code

Discussion in 'Android Questions' started by Johan Schoeman, Mar 11, 2015.

  1. Johan Schoeman

    Johan Schoeman Expert Licensed User

    Cannot figure out why this keeps on generating an error when being compiled with B4A inline java code.

    path.addArc((float) 0.0, (float) 0.0, (float) (targetWidth/2.0), (float) (targetHeight/2.0), (float) 180.0, (float) 100.0);


    B4A version 4.30
    Parsing code. 0.00
    Compiling code. 0.06
    Compiling layouts code. 0.00
    Generating R file. 0.05
    Compiling generated Java code. Error
    javac 1.6.0_15
    src\JHS\BubbleBitmap\main.java:579: addArc(android.graphics.RectF,float,float) in android.graphics.Path cannot be applied to (float,float,float,float,float,float)
    path.addArc((float) 0.0, (float) 0.0, (float) (targetWidth/2.0), (float) (targetHeight/2.0), (float) 180.0, (float) 100.0);
    ^
    1 error

    targetWidth and targetHeight are declared as type int

    It should use
    android.graphics.Path
    that I am already importing. The error above refers to
    addArc(android.graphics.RectF,float,float)....??
     
    Last edited: Mar 11, 2015
  2. JordiCP

    JordiCP Well-Known Member Licensed User

    I think you should first define a Rectf with the four first parameters and then drawPath with Rectf,float,float
     
  3. Johan Schoeman

    Johan Schoeman Expert Licensed User

    The following two methods exist in
    android.graphics.Path

    addArc(RectF oval, float startAngle, float sweepAngle)
    addArc(float left, float top, float right, float bottom, float startAngle, float sweepAngle)

    I am using the second one. Why the error? All floats.
     
    JordiCP likes this.
  4. keirS

    keirS Well-Known Member Licensed User

    B4A doesn't support calling overloaded methods in libraries. I suspect this is true of inline Java within B4A.
     
    JordiCP likes this.
  5. JordiCP

    JordiCP Well-Known Member Licensed User

    Oops! I misunderstood the question o_O
     
  6. DonManfred

    DonManfred Expert Licensed User

    Like @keirS already said; b4a does not allow overloaded versions of methods.

    If you want to use the second version then you create an own name for this in your wrapper

    something like

    Code:
    public void addArc2(float left, float top, float right, float bottom, float startAngle, float sweepAngle) {
             
    path.addArc(left, top, right, bottom, startAngle, swepAngle);
         
    }
     
  7. Johan Schoeman

    Johan Schoeman Expert Licensed User

    Hi @DonManfred. Still a bit confused about this. What causes the overloading? I don't see a method in RectF with the same signature. Or am I misinterpreting some of the methods in RectF?

    Rgds

    JS
     
  8. DonManfred

    DonManfred Expert Licensed User

    Asuming there is a method like this
    Code:
    public void Arc(int Width, int Height) {
        
    }
    you then can, IN JAVA, add an overloaded version of this method

    Code:
    public void Arc(int Width, int Height, int Angle) {
        
    }
    In java you then can use the one with two or the one with three parameters. But the methodname is the same.
     
  9. Johan Schoeman

    Johan Schoeman Expert Licensed User

    Yip - I agree. But I don't see a method with the same signature
    path.addArc((float) 0.0, (float) 0.0, (float) (targetWidth/2.0), (float) (targetHeight/2.0), (float) 180.0, (float) 100.0);
    in RectF.
    RectF has no method requiring 6 float parameters to be passed.....?
     
  10. DonManfred

    DonManfred Expert Licensed User

    RecF is an Javaobject i believe. Not a method

    So. In the overloaded version of Arc the first parameter is not a float; it is a rect i suppose

    Code:
    Rect RecF = new Rect();
     
  11. Johan Schoeman

    Johan Schoeman Expert Licensed User

    Does not make sense to me. Path has two addArc methods

    addArc(RectF oval, float startAngle, float sweepAngle)
    addArc(float left, float top, float right, float bottom, float startAngle, float sweepAngle)

    The first one calls for RectF but the second one does not require RectF. I am trying to use the second method. And it complains about RectF? Major confused here.
     
  12. keirS

    keirS Well-Known Member Licensed User

    B4A can't distinguish between the the two methods so picks the first one it finds. If you want a technical explanation as to why this is the case then ask Erel.
     
  13. thedesolatesoul

    thedesolatesoul Expert Licensed User

    Sorry to disappoint you guys but @keirS and @DonManfred are wrong about overloading issues.
    It actually makes no sense, I dont know where they picked up this idea from.
    It complains about compiling main.java at this point the source is already converted to java.

    Anyway, that particular addArc method was added in API21. Are you compiling with the latest android.jar?
     
    Johan Schoeman, DonManfred and NJDude like this.
  14. keirS

    keirS Well-Known Member Licensed User

    Well one explanation which would make sense is B4A has it's own preprocessor for the Java code. B4A is a compiler in it's own right after all and it's the sort of feature you might expect in a transpiler. It might be a wrong answer but it would make sense.
     
  15. Johan Schoeman

    Johan Schoeman Expert Licensed User

    I will check API level later today - in all probability not having the latest android.jar installed.
     
  16. thedesolatesoul

    thedesolatesoul Expert Licensed User

    Nope. B4A is not preprocessing the java code. It is patched bang in to the java code. The only patching done is on events B4A automatically generates.
    If you actually read the error message, your explanation makes ZERO sense.
    (Atleast to me, until Johan finally comes up and says noooo i have the latest android.jar, then no explanation makes sense to me).

    @Johan Schoeman How about you check it now!?
     
    NJDude likes this.
  17. Johan Schoeman

    Johan Schoeman Expert Licensed User

    At work at present and far away from my home computer. Will check tonight when back home and let you know.

    Rgds

    JS
     
  18. thedesolatesoul

    thedesolatesoul Expert Licensed User

    Thanks, but you really need to install TeamViewer ;)
     
    NJDude likes this.
  19. Johan Schoeman

    Johan Schoeman Expert Licensed User

    Got 19 installed. Busy downloading 22. Will test once installed and let you know :)
     
  20. Johan Schoeman

    Johan Schoeman Expert Licensed User

    The original compiling error now seems to be gone (with API21 installed). Now there is a new error in method getHeartBitmap1 when the B4A project starts execution. Project attached. It is driving me NUTS to the nth degree :mad:! Anyone with any idea what the solution is? (Don't worry about the accuracy of the path. I will sort that later. Just used trial and error to get best estimate of x/y coordinates). But getHeartBitmap1 needs to respond to:
    addArc(float left, float top, float right, float bottom, float startAngle, float sweepAngle)........

    ** Activity (main) Create, isFirst = true **

    java.lang.reflect.InvocationTargetException

    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:130)
    at JHS.BubbleBitmap1.main._activity_create(main.java:344)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
    at JHS.BubbleBitmap1.main.afterFirstLayout(main.java:110)
    at JHS.BubbleBitmap1.main.access$100(main.java:27)
    at JHS.BubbleBitmap1.main$WaitForLayout.run(main.java:88)
    at android.os.Handler.handleCallback(Handler.java:605)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4514)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)

    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
    at dalvik.system.NativeStart.main(Native Method)
    Caused by: java.lang.NoSuchMethodError: android.graphics.Path.addArc
    at JHS.BubbleBitmap1.main.getHeartBitmap1(main.java:407)
    ... 19 more
    java.lang.reflect.InvocationTargetException
     

    Attached Files:

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