B4J Question [SOLVED] Call inline java with double[] param

rosippc64a

Active Member
Licensed User
Longtime User
Hi All!
Sorry for newbie question, but this is the first occassion to do with this kind of params and I can't figure out how to do it:
I can see the error message, but don't know how to solve it...
thanks in advance
B4X:
#AdditionalJar: jama.jar
Sub Process_Globals
    
End Sub

Sub inline As JavaObject
    Return Me
End Sub

Sub AppStart (Args() As String)
    Dim x() As Double =Array As Double(1, 2, 4, 8, 16, 20)
    Dim y() As Double = Array As Double(100, 50, 15, 67, 201, 4)
    Dim d(4,2) As Double = inline.RunMethod("PolyReg", Array(x,y,4)) <-------- what to do (I tried before array as object() also)?
    'Log(d)
End Sub


#if JAVA

public static class PolynomialRegression implements Comparable<PolynomialRegression> {
    public PolynomialRegression(double[] x, double[] y, int degree) {
        this(x, y, degree, "x");
    }
 ...
}
 public double[][] PolyReg(double[] x, double[] y, int degree) {
        PolynomialRegression regression = new PolynomialRegression(x, y, degree);
        return regression.PolyReg(x, y, degree);
 }
#End If

main._appstart (java line: 56)
java.lang.IllegalArgumentException: object is not an instance of declaring class
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
    at b4j.example.main._appstart(main.java:56)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
    at b4j.example.main.main(main.java:30)
 
Last edited:

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Arrays are complicated in between java and b4x, i have found easier to pass the arrays to inline java and convert them there with the array the library is expecting.

here i create an array of an object called fmd, with the fmds (array of objects size) and pass all the items to the new array.

B4X:
Fmd[] fmds2 = new Fmd[fmds.size()];
    
    for (int i = 0; i < fmds.size(); i++) {
            fmds2[i] = (Fmd)fmds.get(i);
        }
 
Upvote 0
Top