Android Question Error NullPointerException using MSDynamicGridView Library

Discussion in 'Android Questions' started by asales, Feb 16, 2016.

  1. asales

    asales Well-Known Member Licensed User

    I'm using the MSDynamicGridView Library (https://www.b4x.com/android/forum/threads/msdynamicgridview-library.49331/page-4) 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?

    Code:
    ~e:main_da_getcontent (java line: 1477)
    ~e:java.lang.NullPointerException: Attempt 
    to read from field 'anywheresoftware.b4a.objects.collections.List br.com.myimages.main._vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv6' on a null object reference
    ~e: at br.com.myimages.main._da_getcontent(main.java:1477)
    ~e: at java.lang.reflect.Method.invoke(Native Method)
    ~e: at java.lang.reflect.Method.invoke(Method.java:
    372)
    ~e: at anywheresoftware.b4a.BA.raiseEvent2(BA.java:
    169)
    ~e: at com.maximussoft.gridviews.B4ADynamicGridAdapter.getView(B4ADynamicGridAdapter.java:
    66)
    ~e: at android.widget.AbsListView.obtainView(AbsListView.java:
    2344)
    ~e: at android.widget.GridView.onMeasure(GridView.java:
    1060)
    ~e: at android.view.View.measure(
    View.java:17448)
    ~e: at android.view.ViewGroup.measureChild(ViewGroup.java:
    5436)
    ~e: at android.view.ViewGroup.measureChildren(ViewGroup.java:
    5413)
    This is my code:
    Code:
    Sub DA_GetLayout(Position As Int, ItemID As Long, ItemTag As StringAs Panel
        
    Dim p As Panel
        p.Initialize(
    "")

        
    Dim iv As ImageView
        iv.Initialize(
    "iv")
        iv.Gravity = 
    Gravity.Fill

        p.AddView(iv, 
    1dip1dip, (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 PanelAs 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), 200200)

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

    Erel Administrator Staff Member Licensed User

    Are you able to reproduce it in debug mode?

    My guess is that GridItems list was not initialized.
     
  3. asales

    asales Well-Known Member Licensed User

    I'll try. Thanks!
     
  4. JohnC

    JohnC Well-Known Member Licensed User

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice