Android Question Program Crash

Keith Yong

Active Member
Licensed User
Longtime User
I'm getting the program crash when I load the layout and I getting the error message as per image attach. I also attach the layout file as well. Appreciate if you can let me know what am I getting wrong. Thanks
Screen Shot 2020-02-26 at 6.56.11 PM.png


B4X:
                Dim p As Panel : p.Initialize("")   
                p.Height = 135dip
                clv.Add(p,"")
                p.LoadLayout("TeeTime")
 

Attachments

  • teetime.zip
    1.9 KB · Views: 102

aeric

Expert
Licensed User
Longtime User
Make sure your golfer.png file is inside Files folder and try click on "Sync" button.
1582715687235.png


If you get the error in log about decoder, there is no way to see the problem without you posting the code.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
To use customlistview, try:
B4X:
Sub Globals
    Private xui As XUI
    Private clv As CustomListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    'Dim p As Panel : p.Initialize("")
    Dim p As B4XView = xui.CreatePanel("")
    'p.Height = 135dip
    p.SetLayoutAnimated(0, 0, 0, clv.AsView.Width, 135dip)
    p.LoadLayout("TeeTime")
    clv.Add(p, "")  
End Sub
 
Upvote 0

Keith Yong

Active Member
Licensed User
Longtime User
To use customlistview, try:
B4X:
Sub Globals
    Private xui As XUI
    Private clv As CustomListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    'Dim p As Panel : p.Initialize("")
    Dim p As B4XView = xui.CreatePanel("")
    'p.Height = 135dip
    p.SetLayoutAnimated(0, 0, 0, clv.AsView.Width, 135dip)
    p.LoadLayout("TeeTime")
    clv.Add(p, "") 
End Sub


I manage to found the problem, it was due to memory issue. In the layout have many image box and it need to display more then 50 rows. It can run on my mobile but it getting crash when I run on 2gb Ram device, even I use clv_VisibleRangeChanged method. If I remove all image box, then it can display.

The image attached was the layout display in my mobile. Appreciate if you can advise me the best way to achieve this in order to show the image.

d1baf153-a5e2-4675-8cf7-b0d9552b8607.jpg

B4X:
If iCount = 1 Then
                lblTBox1.Text = m.Get("TeeBox")
                lblTime1.Text = DateTime.Time(t)
                If m.Get("PaxAllow") <= 3 Then
                    Img1_1.Bitmap = LoadBitmapSample(File.DirAssets, "golfer2.png", 20dip, 20dip)
                    If m.Get("PaxAllow") <= 2 Then
                        Img1_2.Bitmap = LoadBitmapSample(File.DirAssets, "golfer2.png", 20dip, 20dip)
                        If m.Get("PaxAllow") <= 1 Then
                            Img1_3.Bitmap = LoadBitmapSample(File.DirAssets, "golfer2.png", 20dip, 20dip)
                        End If
                    End If
                End If
                
                Panel1.Tag = m
            Else If  iCount = 2 Then
                Panel2.Visible = True
                Panel2.Tag = m
                
                lblTBox2.Text = m.Get("TeeBox")
                lblTime2.Text = DateTime.Time(t)

                If m.Get("PaxAllow") <= 3 Then
                    Img2_1.Bitmap = LoadBitmapSample(File.DirAssets, "golfer2.png", 20dip, 20dip)
                    If m.Get("PaxAllow") <= 2 Then
                        Img2_2.Bitmap = LoadBitmapSample(File.DirAssets, "golfer2.png", 20dip, 20dip)
                        If m.Get("PaxAllow") <= 1 Then
                            Img2_3.Bitmap = LoadBitmapSample(File.DirAssets, "golfer2.png", 20dip, 20dip)
                        End If
                    End If
                End If
            Else If iCount = 3 Then
                Panel3.Visible = True
                Panel3.Tag = m
                
                lblTBox3.Text = m.Get("TeeBox")
                lblTime3.Text = DateTime.Time(t)
                If m.Get("PaxAllow") <= 3 Then
                    Img3_1.Bitmap = LoadBitmapSample(File.DirAssets, "golfer2.png", 20dip, 20dip)
                    If m.Get("PaxAllow") <= 2 Then
                        Img3_2.Bitmap = LoadBitmapSample(File.DirAssets, "golfer2.png", 20dip, 20dip)
                        If m.Get("PaxAllow") <= 1 Then
                            Img3_3.Bitmap = LoadBitmapSample(File.DirAssets, "golfer2.png", 20dip, 20dip)
                        End If
                    End If
                End If
            End If
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Are you using Lazy Loading?

If I remove all image box, then it can display.
How if you permanently load the image? Put the "Active" image on top of the "Inactive" image and set the Visible to True or False. Then you do not need to reload the image many times.

Or try change LoadBitmapSample to LoadBitmapResize ?

1582795833494.png
 
Upvote 0

Keith Yong

Active Member
Licensed User
Longtime User
Are you using Lazy Loading?


How if you permanently load the image? Put the "Active" image on top of the "Inactive" image and set the Visible to True or False. Then you do not need to reload the image many times.

Or try change LoadBitmapSample to LoadBitmapResize ?

View attachment 89240
Yes, I'm using lazy loading.

The crash happen when it load the layout, When I do debug, it manage to load 8 layout, when come to loading 9th layout, it getting crash.
 

Attachments

  • 70ba490d-f92f-40ff-8c9b-55c57a855b59.jpg
    70ba490d-f92f-40ff-8c9b-55c57a855b59.jpg
    43.1 KB · Views: 89
Upvote 0

aeric

Expert
Licensed User
Longtime User
I tried this code in emulator and load without error.

B4X:
Sub Globals
    Private xui As XUI
    Private clv As CustomListView
    Type CardData (TeeBox As String, TeeTime As String, PaxAllow As Int)
    Private lblTBox1 As B4XView
    Private lblTime1 As B4XView
    Private Img1_1 As B4XView
    Private Img1_2 As B4XView
    Private Img1_3 As B4XView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    For i = 0 To 199
        Dim cd As CardData
        cd.Initialize
        cd.TeeBox = "1"
        cd.TeeTime = "7:00 AM"
        cd.PaxAllow = 1
        Dim p As B4XView = xui.CreatePanel("")
        p.SetLayoutAnimated(0, 0, 0, clv.AsView.Width, 135dip)
        clv.Add(p, cd)
    Next
End Sub

Sub clv_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
    Dim ExtraSize As Int = 20
    For i = 0 To clv.Size - 1
        Dim p As B4XView = clv.GetPanel(i)
        If i > FirstIndex - ExtraSize And i < LastIndex + ExtraSize Then
            'visible+
            If p.NumberOfViews = 0 Then
                Dim cd As CardData = clv.GetValue(i)
                p.LoadLayout("TeeTime")
                lblTBox1.Text = cd.TeeBox
                lblTime1.Text = cd.TeeTime
                If cd.PaxAllow <= 3 Then
                    Img1_1.SetBitmap(LoadBitmapResize(File.DirAssets, "golfer2.png", 20dip, 20dip, True))
                    If cd.PaxAllow <= 2 Then
                        Img1_2.SetBitmap(LoadBitmapResize(File.DirAssets, "golfer2.png", 20dip, 20dip, True))
                        If cd.PaxAllow <= 1 Then
                            Img1_3.SetBitmap(LoadBitmapResize(File.DirAssets, "golfer2.png", 20dip, 20dip, True))
                        End If
                    End If
                End If
            End If
        Else
            'not visible
            If p.NumberOfViews > 0 Then
                p.RemoveAllViews '<--- remove the layout
            End If
        End If
    Next
End Sub
 
Upvote 0

Keith Yong

Active Member
Licensed User
Longtime User
I tried this code in emulator and load without error.

B4X:
Sub Globals
    Private xui As XUI
    Private clv As CustomListView
    Type CardData (TeeBox As String, TeeTime As String, PaxAllow As Int)
    Private lblTBox1 As B4XView
    Private lblTime1 As B4XView
    Private Img1_1 As B4XView
    Private Img1_2 As B4XView
    Private Img1_3 As B4XView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    For i = 0 To 199
        Dim cd As CardData
        cd.Initialize
        cd.TeeBox = "1"
        cd.TeeTime = "7:00 AM"
        cd.PaxAllow = 1
        Dim p As B4XView = xui.CreatePanel("")
        p.SetLayoutAnimated(0, 0, 0, clv.AsView.Width, 135dip)
        clv.Add(p, cd)
    Next
End Sub

Sub clv_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
    Dim ExtraSize As Int = 20
    For i = 0 To clv.Size - 1
        Dim p As B4XView = clv.GetPanel(i)
        If i > FirstIndex - ExtraSize And i < LastIndex + ExtraSize Then
            'visible+
            If p.NumberOfViews = 0 Then
                Dim cd As CardData = clv.GetValue(i)
                p.LoadLayout("TeeTime")
                lblTBox1.Text = cd.TeeBox
                lblTime1.Text = cd.TeeTime
                If cd.PaxAllow <= 3 Then
                    Img1_1.SetBitmap(LoadBitmapResize(File.DirAssets, "golfer2.png", 20dip, 20dip, True))
                    If cd.PaxAllow <= 2 Then
                        Img1_2.SetBitmap(LoadBitmapResize(File.DirAssets, "golfer2.png", 20dip, 20dip, True))
                        If cd.PaxAllow <= 1 Then
                            Img1_3.SetBitmap(LoadBitmapResize(File.DirAssets, "golfer2.png", 20dip, 20dip, True))
                        End If
                    End If
                End If
            End If
        Else
            'not visible
            If p.NumberOfViews > 0 Then
                p.RemoveAllViews '<--- remove the layout
            End If
        End If
    Next
End Sub
I tried the code given. It can work for mobile, but doesn't work for device I tested. I debug each line and it always happen when it need to load the layout 9th times.

Screen Shot 2020-02-28 at 10.35.51 AM.png

after above after line run, the app getting crash on the decide and return the following error message in the log
Screen Shot 2020-02-28 at 10.36.22 AM.png


I create another layout (TeeTime2) to remove the entire image box, then system is working fine. It is because of the image box taking a lot memory use?
 

Attachments

  • B4A.zip
    401.3 KB · Views: 84
Upvote 0

aeric

Expert
Licensed User
Longtime User
Try:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")
    
'    Dim p As B4XView = xui.CreatePanel("")
'    p.Height = 135dip
'    clv.Add(p,"")
'    p.LoadLayout("TeeTime")
    LoadData
End Sub
 
Upvote 0

Keith Yong

Active Member
Licensed User
Longtime User
Try:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")
   
'    Dim p As B4XView = xui.CreatePanel("")
'    p.Height = 135dip
'    clv.Add(p,"")
'    p.LoadLayout("TeeTime")
    LoadData
End Sub

It doesnt help. the error now happen when it load 10th layout. It is showing new error msg when I connect to another Kiosk machine.

Screen Shot 2020-02-28 at 1.46.40 PM.png
 
Upvote 0

Keith Yong

Active Member
Licensed User
Longtime User
B4X:
'                If cd.PaxAllow <= 3 Then
'                    Img1_1.SetBitmap(LoadBitmapResize(File.DirAssets, "golfer2.png", 20dip, 20dip, True))
'                    If cd.PaxAllow <= 2 Then
'                        Img1_2.SetBitmap(LoadBitmapResize(File.DirAssets, "golfer2.png", 20dip, 20dip, True))
'                        If cd.PaxAllow <= 1 Then
'                            Img1_3.SetBitmap(LoadBitmapResize(File.DirAssets, "golfer2.png", 20dip, 20dip, True))
'                        End If
'                    End If
'                End If

In fact I remark the rows not run, but still the same.
 
Upvote 0
Top