Android Question #AdditionalJar.... how to pass array of objects in constructor?

PaulR

Active Member
Licensed User
Longtime User
I am attempting to create an instance of a class that requires an array of an specific type of object in the constructor. The log shows that the constructor is not found which I assume is because Object[] is being passed, as opposed to an array of the correct type.
B4X:
Dim jo, gvd1, gvd2, gvd2 As JavaObject
    Dim a As Double = 1.  :     Dim d As Double = 2.
    gvd1 = jo.InitializeNewInstance(pck&"GraphView.GraphViewData", Array(a, d))
    a = 2 : d=1.5   
    gvd2 = jo.InitializeNewInstance(pck&"GraphView.GraphViewData", Array(a, d))

    'constructor not found thrown here... constructor expects GraphViewData[]
    exampleSeries=jo.InitializeNewInstance(pck&"GraphViewSeries", Array(Array(gvd1, gvd2)))

(using GraphView library)

What would be the solution in these cases?

ps, I know the library is partially wrapped for b4a already, but it doesn't work in Portrait over here and that's not the point anyway :)
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Good timing! JavaObject.InitializeArray will be added to JavaObject when B4A v3.80 is released (next week):
upload_2014-5-16_11-16-24.png


B4X:
#AdditionalJar: graphview-3.1

Sub Activity_Create(FirstTime As Boolean)
   Dim gvdArray As JavaObject
   gvdArray.InitializeArray("com.jjoe64.graphview.GraphView.GraphViewData", Array( _
     CreateGVD(1, 2), _
     CreateGVD(2, 1.5), _
     CreateGVD(3, 2.5), _
     CreateGVD(4, 1)))
   Dim gvs As JavaObject
   gvs.InitializeNewInstance("com.jjoe64.graphview.GraphViewSeries", Array(gvdArray))
   Dim graphView As JavaObject
   graphView.InitializeNewInstance("com.jjoe64.graphview.LineGraphView", _
     Array(GetContext, "title")).RunMethod("addSeries", Array(gvs))
   Activity.AddView(graphView, 0, 0, 100%x, 100%y)
End Sub

Sub CreateGVD(x As Double, y As Double) As JavaObject
   Dim jo As JavaObject
   jo.InitializeNewInstance("com.jjoe64.graphview.GraphView.GraphViewData", Array(x, y))
   Return jo
End Sub
 
Upvote 0

PaulR

Active Member
Licensed User
Longtime User
Great stuff Erel, looking forward to the update. This new functionality is great news for easy integration of 3rd party code and creation of libraries!
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Upvote 0
Top