Sergey_New Well-Known Member Licensed User Longtime User Sep 29, 2023 #1 The following code throws an error when sorting the list: java.lang.NoSuchFieldException: No field name in class Lsv/bystrovzorov/classrepository; (declaration of 'sv.bystrovzorov.classrepository' appears in base.apk) What is the reason? [CODE lang="b4x" title="ClassRepository"]Sub Class_Globals Public name As String, address As ClassAddress, notes As List End Sub Public Sub Initialize address.Initialize notes.Initialize End Sub[/CODE] [CODE lang="b4x" title="Activity"]Dim lst As List lst.Initialize For Each k As String In parser.db.repositories.Keys If parser.db.repositories.ContainsKey(k) Then Dim repo As ClassRepository=parser.db.repositories.Get(k) lst.Add(repo) End If Next lst.SortType("name",True)[/CODE]
The following code throws an error when sorting the list: java.lang.NoSuchFieldException: No field name in class Lsv/bystrovzorov/classrepository; (declaration of 'sv.bystrovzorov.classrepository' appears in base.apk) What is the reason? [CODE lang="b4x" title="ClassRepository"]Sub Class_Globals Public name As String, address As ClassAddress, notes As List End Sub Public Sub Initialize address.Initialize notes.Initialize End Sub[/CODE] [CODE lang="b4x" title="Activity"]Dim lst As List lst.Initialize For Each k As String In parser.db.repositories.Keys If parser.db.repositories.ContainsKey(k) Then Dim repo As ClassRepository=parser.db.repositories.Get(k) lst.Add(repo) End If Next lst.SortType("name",True)[/CODE]
LucaMs Expert Licensed User Longtime User Sep 29, 2023 #2 Sergey_New said: lst.SortType("name",True) Click to expand... SortType works with custom types, not classes. Upvote 1
Sergey_New said: lst.SortType("name",True) Click to expand... SortType works with custom types, not classes.
LucaMs Expert Licensed User Longtime User Sep 29, 2023 #3 This check is superfluous: Sergey_New said: If parser.db.repositories.ContainsKey(k) Then Click to expand... Upvote 0
This check is superfluous: Sergey_New said: If parser.db.repositories.ContainsKey(k) Then Click to expand...
Sergey_New Well-Known Member Licensed User Longtime User Sep 29, 2023 #4 LucaMs said: SortType works with custom types, not classes. Click to expand... Added to Globals B4X: Type repo2(name As String, address As ClassAddress,notes As List) [CODE lang="b4x" title="Activity"] Dim lst As List lst.Initialize For Each k As String In parser.db.repositories.Keys Dim repo As ClassRepository=parser.db.repositories.Get(k) Dim rp2 As repo2 rp2.name=repo.name rp2.address=repo.address rp2.notes=repo.notes lst.Add(rp2) Next lst.SortType("name",True)[/CODE] It works. Is it possible to make it simpler? If my memory serves me correctly, VB has the ability to sort classes. Upvote 0
LucaMs said: SortType works with custom types, not classes. Click to expand... Added to Globals B4X: Type repo2(name As String, address As ClassAddress,notes As List) [CODE lang="b4x" title="Activity"] Dim lst As List lst.Initialize For Each k As String In parser.db.repositories.Keys Dim repo As ClassRepository=parser.db.repositories.Get(k) Dim rp2 As repo2 rp2.name=repo.name rp2.address=repo.address rp2.notes=repo.notes lst.Add(rp2) Next lst.SortType("name",True)[/CODE] It works. Is it possible to make it simpler? If my memory serves me correctly, VB has the ability to sort classes.
LucaMs Expert Licensed User Longtime User Sep 29, 2023 #5 Sergey_New said: Is it possible to make it simpler? Click to expand... I don't think so, that seems to me to be the most logical, clean and correct method. [Just a note, perhaps superfluous: if you were to serialize custom type objects, they must necessarily be declared in the Main or in the B4XMainPage] Upvote 0
Sergey_New said: Is it possible to make it simpler? Click to expand... I don't think so, that seems to me to be the most logical, clean and correct method. [Just a note, perhaps superfluous: if you were to serialize custom type objects, they must necessarily be declared in the Main or in the B4XMainPage]
Sergey_New Well-Known Member Licensed User Longtime User Sep 29, 2023 #6 LucaMs said: I don't think so, that seems to me to be the most logical, clean and correct method. Click to expand... Thank you! Upvote 0
LucaMs said: I don't think so, that seems to me to be the most logical, clean and correct method. Click to expand... Thank you!