Android Question Help with troubleshooting in CustomListView

strupp01

Active Member
Licensed User
Longtime User
I created a program that runs on one tablet with Android 14 and another tablet with Android 16.

There are no problems with Android 14. With Android 16, the following error message appears:


1770897847806.png



I can't make sense of this error message. There's also no line number indicating where the program crashes.

However, I now know which subroutine causes the program to crash.

B4X:
Sub CustomListView_Einzelner_Bericht_Ausgaben_Kategorien_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
    If (CustomListView_Einzelner_Bericht_Ausgaben_Kategorien.Size - 1) > 0 Then
        Dim ExtraSize As Int = 15 'List size
        For i = Max(0, FirstIndex - ExtraSize) To Min(LastIndex + ExtraSize, CustomListView_Einzelner_Bericht_Ausgaben_Kategorien.Size - 1)
            Dim Pnl As B4XView = CustomListView_Einzelner_Bericht_Ausgaben_Kategorien.GetPanel(i)
            If Pnl.NumberOfViews = 0 Then
                Log(i)
'                If i > 0 Then
                If i > 0 Then    'Anzahl_Kategorien_mit_Geld - 1 Then    'List_Kategorien_Geld.size - 1 Then
                    Canvas1.Initialize(Panel_einzelne_Aktion)
                    Canvas1.DrawLine(0dip, 73dip, 740dip, 73dip, Colors.Black, 5dip)

                    Pnl.LoadLayout("cellItem")
                    Dim DD As DatanInfoAusgabenKategorie = CustomListView_Einzelner_Bericht_Ausgaben_Kategorien.GetValue(i)
                   
                    Label_Kategorie.TextColor = Colors.ARGB(255,31,122,31)
                    Label_Geldbetrag.TextColor = Colors.ARGB(255,31,122,31)
                   
                    LabelKontoaktion.Text = DD.Ausgaben_Name
                    Label_Kategorie.Text = DD.Kategorie
                    Label_Datum.Text = DD.Datum
                    Label_Geldbetrag.Text = $"${NumberFormat2(DD.Summe_Ausgaben, 1, 2, 2, False)} ${DD.Text_Waehrung_Abkuerzung}"$
                    ImageView_Icon.SetBitmap(xui.LoadBitmapResize(File.DirAssets, DD.Speicherpfad_Icon, ImageView_Icon.Width, ImageView_Icon.Height, True))
                Else
                    Pnl.LoadLayout("cellItem_Bericht_Ausgaben_Kategorie")
                    Dim DD As DatanInfoAusgabenKategorie = CustomListView_Einzelner_Bericht_Ausgaben_Kategorien.GetValue(i)
                   
                    Label_Kategorie.TextColor = Colors.Black        '.ARGB(255,31,122,31)
                    Label_Geldbetrag.TextColor = Colors.ARGB(255,31,122,31)
                   
                    Label_Kategorie.Text = DD.Kategorie
                    B4XProgressBar_Prozente.Progress = DD.Balkenlaenge
                   
                    'Prozentzahl hinter Balken eintragen
                    Label_Prozent.Initialize("Label_Prozent")
                    Label_Prozent.TextColor = Colors.Black
                    Label_Prozent.Gravity = Gravity.LEFT
                    Label_Prozent.Typeface = Typeface.DEFAULT_BOLD
                    Label_Prozent.TextSize = 24
                    Label_Prozent.Text = NumberFormat2(DD.Prozentanteil_Wert, 1, 2, 2, False) & " %"
                   
                    Dim Temp As Int
                    Temp = (300 / 100 * DD.Balkenlaenge) * 2.5
                    Pnl.AddView(Label_Prozent, Temp + 30dip, 32dip, 110dip, 30dip)'((400)/Ausgangswert * DD.Prozentanteil_Wert), 32dip, 100dip, 30dip)
                   
                    Label_Geldbetrag.Text = $"${NumberFormat2(DD.Summe_Ges_Kategorie, 1, 2, 2, False)} ${DD.Text_Waehrung_Abkuerzung}"$
                End If
'                End If
            End If
        Next
    End If
End Sub

I'm using the same subroutine, but with income instead of expenses, and there are no problems.

If I set a breakpoint in the loop I so that it always pauses at that point, the program also runs without any issues.

I can't upload the program because it's too large and the data is personal.

Perhaps someone has an idea where the problem lies and can help me.

Thank you in advance.

Regards, strupp01
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Better to copy logs as text (right click) and post instead of screenshot.

Try to use lazy loading to load the items, refer to this
This is indeed the solution. The error happens where there are many views and the OS saves the Activity state when the activity is paused.
 
Upvote 0

strupp01

Active Member
Licensed User
Longtime User
I've double-checked everything. I'm loading the data in 747ms. Despite this, the program keeps crashing with an error message. If I stop the program after loading or at the beginning of the output using a breakpoint, it runs without any problems. I can't find a solution.
 
Upvote 0

strupp01

Active Member
Licensed User
Longtime User
I've been looking into lazy loading, but haven't made any difference. Either I haven't grasped it, or something else is causing the program to crash. It's also strange that another module with 5000 entries works perfectly. It crashes with 80 entries.

I've attached the module where the error occurs.

Perhaps someone will spot my mistake there. I'm completely stuck.
 

Attachments

  • Einzelner_Bericht_Ausgaben_Kategorie.bas
    31.6 KB · Views: 22
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
I understand why you cannot supply a complete sample of code and data. I have looked (briefly) at your code sample in your last post. I think that it is very unlikely that anyone will spot the problem in those 200 lines of code, if indeed the problem is there.

In your first post you say that you can identify the subroutine in which the crash occurs. If that is the case then start putting Log statements into that subroutine. You should then be able to detect between which two Log statements the crash occurs. Then add more Log statements between those two statements to narrow down the fault location - eventually you should be able to find the line at which the program crashes.

It's also strange that another module with 5000 entries works perfectly. It crashes with 80 entries.

I am not sure what this statement means - that a "module has 5000 entries". If you mean that your code works with 5000 data records but crashes after processing 80 different data records then that would suggest to me that perhaps the problem lies in the data, not in the program code. Or, to be more correct, that the program is unable to recognise invalid data.
 
Upvote 0

strupp01

Active Member
Licensed User
Longtime User
My database has approximately 5000 records in total. Additionally, some databases contain only outputs, others only inputs, and so on.

I can display the complete database of 5000 records without any problems. However, the smaller database with approximately 80 records results in an error. Another user suggested this might be due to lazy loading, which Erel also confirmed.

I looked at the example provided and adapted my program accordingly. Despite this, the same error occurs.

If I create a breakpoint somewhere, the program runs without errors.

I'm at a loss and don't know what to do next.
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
I'm at a loss and don't know what to do next.

You said, in your first post, that "I now know which subroutine causes the program to crash." I have suggested how you can investigate that subroutine (if that is indeed the source of your problem) to find out at which statement the problem occurs. Why do you not do that next?
 
Upvote 0

strupp01

Active Member
Licensed User
Longtime User
The program executes the following 15 times:

Sub CustomListView_Einzelner_Bericht_Ausgaben_Kategorien_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)

completely, and then the error message appears.
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
Here is my understanding of your situation. You have two devices, let us call them Device A and Device B, and two data sets, Dataset X and Dataset Y. The data sets are SQL databases. You have a single program that you run on both Device A and Device B. The program is identical on both devices - same code and same manifest.

These situations apply :
- Device A using Dataset X runs successfully..
- Device B using Dataset Y processes some records but then fails.

Can you run Dataset X on Device B, and Dataset Y on Device A? If so what results do you get?

The reason that this information would be useful is that I believe the problem could lie in the data. I say this for these reasons :

- Your code runs on Device A with Dataset X which proves that your code is viable.
- Your code on Device B with Dataset Y appears to process a number of records before it fails, which suggests that the data plays a part in the failure.
- Your code sample shows that you use non-parameterised queries, which is problematic and might result in data being written that cannot be read back.

However there are other factors which point away from a data error. Erel and TeddyBear both suggest a timing problem that might be fixed by lazy-loading, and Erel is seldom mistaken. But you say that you have taken their advice and the problem persists. Nonetheless running with a breakpoint appears to fix the problem and this also suggests a timing condition.

Whether you follow my suggestion or not is up to you, but in any case try something because you need more information.
 
Upvote 0

strupp01

Active Member
Licensed User
Longtime User
I swapped the databases between the two tablets. The result is the same as before. The tablet with Android 14 runs on Android 16 but crashes with the same error message.
 
Upvote 0

zed

Well-Known Member
Licensed User
Android uses an internal mechanism called a Binder to pass data between processes (or between components like Activity to system).
This mechanism has a strict limit: approximately 1 MB for the entire message, but in practice, it's best to stay well below that.
In your case, Android is trying to save the activity's state, and the Bundle contains android:viewHierarchyState = 587 856 bytes and android:views = 587 252 bytes

That's huge.
Android can't transmit that, so it crashes.

Try disabling automatic saving of view states. Something like this: SetActivityAttribute("android:saveEnabled", "false")

Avoid putting large lists, bitmaps, or complex objects in a Bundle.

Your activity contains too many views, or Android is trying to save too much information in the Bundle.

The Bundle is exceeding its limit, resulting in a crash.

Solution: Reduce the data saved by the activity or disable automatic saving.
 
Upvote 0

strupp01

Active Member
Licensed User
Longtime User
What I don't understand is this:

- Why does the program run without problems on Android 14?

- I start my program and then the module with 80 data records, which then crashes. Nothing else runs in the background. If I do the same with a different module that outputs 5000 data records in the same way, everything works perfectly.
 
Upvote 0

zed

Well-Known Member
Licensed User
Perhaps you simply have a problem with the data.
If we can't try a project that exhibits the issue, we can't properly help you. We could say anything and everything and still be stuck on this problem for a week without finding a solution.
 
Upvote 0

strupp01

Active Member
Licensed User
Longtime User
I understand that and have to accept that no one can help me. I copied the data from one tablet to the other, but the same error occurs. I'll try creating dummy data and using a simplified program to see if the error still happens. This will just take some time. Thanks for everyone's help. I'll get back to you when I have an update.
 
  • Like
Reactions: zed
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
If you feel that no one can help you that is partly because you are very unclear in describing your problem. The sentence . . .

I copied the data from one tablet to the other, but the same error occurs.

. . . is totally unhelpful. Which data set is "the data"? Which tablet is "the other tablet"? In your earlier post #13 . . .

The tablet with Android 14 runs on Android 16 but crashes with the same error message.

. . . is equally unclear.

If one set of data fails on both tablets then that is a very different situation than different data sets failing on the same tablet. At the moment I cannot work out which, if either, of these two cases occur. And there is no evidence yet to relate the problem to the Android version - presumably your two tablets have different amounts of memory and different installed apps.
 
Upvote 0
Top