Android Question Error NullPointerException using MSDynamicGridView Library


Well-Known Member
Licensed User
Longtime User
I'm using the MSDynamicGridView Library ( from @thedesolatesoul to display images, since was release.

I update to the B4A 5.8 and move some variables from Main to Starter (the list with the names of file of imagens remains in the Main).

Now, in some devices I get this error (in others the error not occours).
I don't know the causes and how to fix it.
Someone that uses this library have the same issue?

~e:main_da_getcontent (java line: 1477)
~e:java.lang.NullPointerException: Attempt to read from field 'anywheresoftware.b4a.objects.collections.List' on a null object reference
~e: at
~e: at java.lang.reflect.Method.invoke(Native Method)
~e: at java.lang.reflect.Method.invoke(
~e: at anywheresoftware.b4a.BA.raiseEvent2(
~e: at com.maximussoft.gridviews.B4ADynamicGridAdapter.getView(
~e: at android.widget.AbsListView.obtainView(
~e: at android.widget.GridView.onMeasure(
~e: at android.view.View.measure(
~e: at android.view.ViewGroup.measureChild(
~e: at android.view.ViewGroup.measureChildren(

This is my code:
Sub DA_GetLayout(Position As Int, ItemID As Long, ItemTag As String) As Panel
    Dim p As Panel

    Dim iv As ImageView
    iv.Gravity = Gravity.Fill

    p.AddView(iv, 1dip, 1dip, (pnlGrid.Width/NumCols)-2dip, (pnlGrid.Width/NumCols)-2dip)
    Return p
End Sub

Sub DA_GetContent(Position As Int, ItemID As Long, ItemTag As String, ContentPanel As Panel) As Panel
    Try 'change to capture the exception
        Dim iv1 As ImageView = ContentPanel.GetView(0)

        ContentPanel.Color = Colors.White

        Dim Bitmap1 As Bitmap
        Bitmap1.InitializeSample(File.DirAssets, GridItems.Get(ItemID), 200, 200)

        iv1.Bitmap = Bitmap1
        iv1.Visible = True 
        ToastMessageShow(LastException.Message & " - " & ItemID, False)
        Log("ItemID: " & ItemID)
    End Try
    Return ContentPanel
End Sub


Licensed User
Longtime User
Upvote 0