Android Question [SOLVED] How-to covert jar function with inline @Override to JavaObject?

chuath

Member
Licensed User
Longtime User
I am trying to access a jar file "stock-chart.jar" using B4A with JavaObject

The example for this can be found here
http://stockchartview.org/wiki/android/getting-started/

I've solved most of the problem faced and left this one which i can't find any example to rely on to use in JavaObject

The java code i am having problem with is this
B4X:
price.setPointAdapter(new IPointAdapter()
        {
            private final StockPoint fPoint = new StockPoint();
            @Override
            public int getPointCount()
            {
                return points.length;
            }
            @Override
            public AbstractPoint getPointAt(int i)
            {
                Point p = points[i];
                fPoint.setValues(p.o, p.h, p.l, p.c);
                return fPoint;
            }
        });

The closest solution i could think of is to use the CreateEvent
B4X:
Dim StockPriceSeries As JavaObject

StockChartView.InitializeNewInstance("org.stockchart.StockChartView", Array(GetContext))
PriceArea = StockChartView.RunMethodJO("addArea", Null)
StockPriceSeries = StockChartView.RunMethodJO("addSeries", Array(PriceArea))
StockPriceSeries.RunMethod("setPointAdapter" , Array(StockChartView.CreateEvent("org.stockchart.series.Series.IPointAdapter", "StockPointAdapter", Null)))
It can compile without any errors. The question now is i am not sure how do i define this "StockPointAdapter"

From the java code it looks like a class as there are multiple functions under it.
Therefore calling it as StockPointAdapter_Event might not be appropriate.
Maybe i should be using StockPointAdapter_getPointCount and StockPointAdapter_getPointAt ?
or do i create a class module for it?

The error log in B4A 5.5 indicate that i have a NullPointerException
B4X:
java.lang.NullPointerException: Expected to unbox a 'int' primitive type but was returned null
    at $Proxy0.getPointCount(Unknown Source)
    at org.stockchart.series.Series.getPointCount(Series.java:405)
    at org.stockchart.series.Series.hasPoints(Series.java:282)
    at org.stockchart.StockChartView.calcAutoValues(StockChartView.java:1167)

can any kind soul please point me in the correct direction? thanks.
 

chuath

Member
Licensed User
Longtime User
I would like to clarify 3 things.

1) Does it means that the CreateEvent approach is correct in this instance?
2) In the JAVA code, there are 2 override function within it. How do i achieve this inside the event sub? Sub within Sub?
3) I am familiar with event sub. But my problem is the 2 override functions "getPointCount" and "getPointAt". need help on this.

Thanks.
 
Upvote 0

chuath

Member
Licensed User
Longtime User
Thanks ! I think i've got it working (sort of) already.

B4X:
Sub StockPointAdapter_Event (MethodName As String, Args As Object) As Object
   
    If MethodName = "getPointCount" Then
        Return 0
    Else
    If MethodName = "getPointAt" Then
        Return Null
    End If        
    End If
End Sub

Something that looks like this. :)
 
Upvote 0
Top