Android Question MpAndroidChart NullPointerException in CLV

jtare

Active Member
Licensed User
Longtime User
I implemented successfully the MpAndroidChart library as the examples describes. Now I want to move the charts to a CLV so I can show a variable amount of charts depending on the user preference.

My first approach to this was to create the CLV in the designer and the item that will be added, in this case a chart.(Both created in the designer). The I add the item like this:
B4X:
clv.Add(CreateListItemChart("Visits",clv.AsView.Width,110dip),"visits")
Sub CreateListItemChart(text As String, Width As Int, Height As Int) As Panel
    Dim p As Panel
    p.Initialize("")
    p.SetLayout(0, 0, Width, Height)
    p.LoadLayout("itemChart")
    Return p
End Sub
Then plot the data.
B4X:
For i=0 To clv.Size-1
   Dim panel As Panel = clv.GetPanel(i)
   Dim mlc As CombinedChart = panel.GetView(0)     
   draw_graph(mlc)
Next
But here I get a null pointer exception.
If instead of getting each panel and getting the chart view as described above, I generate the variable with the designer name like this: (With only one item on the CLV)
B4X:
Sub Globals
  Private mlc2 As CombinedChart
End Sub

I don't get the null pointer exception, but I don`t have the ability to choose the chart item from the list.


Looking in the source code of the library, I think that the CombinedChart variable "cv" is no being initialized but even if I initialize it I get the same error.

It only seems to work if I set variable in the global sub and use the same name of variable that the view name added in the designer.

Have someone been able to successfully add charts to CLV?
 

Mahares

Expert
Licensed User
Longtime User
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…