Android Question Error when compiling B4A project with inline Java Code

Johan Schoeman

Expert
Licensed User
Longtime 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:

JordiCP

Expert
Licensed User
Longtime User
I think you should first define a Rectf with the four first parameters and then drawPath with Rectf,float,float
 
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime 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.
 
Upvote 0

keirS

Well-Known Member
Licensed User
Longtime User
B4A doesn't support calling overloaded methods in libraries. I suspect this is true of inline Java within B4A.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
am using the second one. Why the error?
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

B4X:
     public void addArc2(float left, float top, float right, float bottom, float startAngle, float sweepAngle) {
         path.addArc(left, top, right, bottom, startAngle, swepAngle);
     }
 
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime 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

B4X:
     public void addArc2(float left, float top, float right, float bottom, float startAngle, float sweepAngle) {
         path.addArc(left, top, right, bottom, startAngle, swepAngle);
     }
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
 
Upvote 0

DonManfred

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

B4X:
    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.
 
Upvote 0

Johan Schoeman

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

B4X:
    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.
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.....?
 
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime 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.
 
Upvote 0

keirS

Well-Known Member
Licensed User
Longtime 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.

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.
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime 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?
 
Upvote 0

keirS

Well-Known Member
Licensed User
Longtime 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?

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.
 
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime 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?
I will check API level later today - in all probability not having the latest android.jar installed.
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime 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.
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!?
 
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime 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!?
At work at present and far away from my home computer. Will check tonight when back home and let you know.

Rgds

JS
 
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime 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!?
Got 19 installed. Busy downloading 22. Will test once installed and let you know :)
 
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime 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
 

Attachments

  • BubbleBitmap1.zip
    57.3 KB · Views: 174
Upvote 0
Top