Android Question Getting error in CustomListView

AndroidMadhu

Active Member
Licensed User
Hello,
I am getting the error intermittently while running xcustomlistview.
The below is the code :

B4X:
Private Label1 As B4XView
    Private Label2 As B4XView
    Private CustomListView1 As CustomListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("xclv")
    Dim xui As XUI
    For i=0 To 49
        Dim p As B4XView=xui.CreatePanel("")
        p.SetLayoutAnimated(100,0,0,100%x,40dip)
        p.LoadLayout("LisLoad")
        Label1.Text=i
        Label2.Text="The Item No is : " & i
        CustomListView1.Add(p,"")
    Next

End Sub
Am I getting the below error:
B4X:
Error occurred on line: 40 (Main)
java.lang.NullPointerException: Attempt to invoke virtual method 'int anywheresoftware.b4a.objects.collections.List.getSize()' on a null object reference
    at b4a.example3.customlistview._add(customlistview.java:71)
    at b4a.example.main._activity_create(main.java:417)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at b4a.example.main.afterFirstLayout(main.java:104)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:82)
    at android.os.Handler.handleCallback(Handler.java:790)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:7025)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)

Please advice
 

AndroidMadhu

Active Member
Licensed User
The below code running at my device....
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
   
    Private Label1 As B4XView
    Private Label2 As B4XView
    Private CustomListView1 As CustomListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("xclv")
    Dim xui As XUI
    For i=0 To 49
        Dim p As B4XView=xui.CreatePanel("")
        p.SetLayoutAnimated(100,0,0,100%x,90dip)
        p.LoadLayout("LisLoad")
        Label1.Text=i
        Label1.TextColor=Colors.Black
        Label2.Text="The Item No is : " & i
        Label2.TextColor=Colors.Black
        CustomListView1.Add(p,"")
    Next

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…