Passing a Float Array to a method with a Reflector

Roger Garstang

Well-Known Member
Licensed User
Longtime User
I know this is probably simple, but I can't get this to work. I need to pass a float[] to a method, how is that wrote in a Reflector?

From the documentation it looks like the type is "[F"...I've tried "java.lang.float" too, but neither work. I'm guessing I'm not using the correct RunMethod- I've tried 2 and 4. I looked at RunPublicmethod, but can't figure out what it is wanting for the Class stuff. setCornerRadii is a Public method though.
 

agraham

Expert
Licensed User
Longtime User
You don't say what object you are trying this on, don't give the code you are using nor the error that you get, so guessing what you are doing wrong is a little difficult. :(

If it's a GradientDrawable, for example, it should be something like
B4X:
Dim radii(8) As Float
....
Obj1.Target = MyGradientDrawable
Obj1.RunMethod2("setCornerRadii", radii, "[F")
If that doesn't work post a simple project that fails.
 
Upvote 0

Roger Garstang

Well-Known Member
Licensed User
Longtime User
Yes, it is a GradientDrawable I am using for the states of a button. I got it working fine with the built in code, but wanted to have different or no radius curves on specific corners of the button. When I try it formatted how you did above it comes back with:

B4X:
ref.RunMethod2(\
javac 1.7.0_03
src\com\primarymarking\etwist\cases.java:326: error: no suitable method found for NumberToString(float[])
_ref.RunMethod2("setCornerRadii",BA.NumberToString(_radii),"[F");
                                   ^
    method BA.NumberToString(long) is not applicable
      (actual argument float[] cannot be converted to long by method invocation conversion)
    method BA.NumberToString(int) is not applicable
      (actual argument float[] cannot be converted to int by method invocation conversion)
    method BA.NumberToString(double) is not applicable
      (actual argument float[] cannot be converted to double by method invocation conversion)
1 error
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
The penny has just dropped - I've not done any Android work for quite a while now so I'm very rusty. RunMethod2 of course takes a string parameter, you need an object parameter variant to pass an array.

B4X:
Obj1.RunMethod4("setCornerRadii", Array As Object( radii ) Array As String( "[F" ))
 
Upvote 0
Top