Android Question List.Get Error

shaffnert03

Member
Licensed User
Longtime User
I have an issue in which I seem to be getting an error when running. The program closes when I try to execute line 134, and this seems to happen no matter what data type the temp variable is (I've tried object, string, list, listview). As best I can tell the list.get command is failing somehow, but I can't think of any other variations that might be causing this.

Included is a screenshot of the program taken while running. Top left is the code (problem line is the first one with debug option on), bottom left is the expanded list of contents of the ViewList variable, and right is the error I get when the program fails (which oddly references a function in the CustomListView module that I'm not even calling here).

Any help would be much appreciated! Also, code for the sub in question is here below. The problem line is temp=ViewList.Get(1)

B4X:
Sub CheckUncheckButton_CheckedChange(Checked As Boolean)
    Dim ViewList As List
    Dim ListSize As Int
    Dim CurrContact As cuContact
    ListSize = ContactsCustListView.getsize
    For i = 0 To ListSize-1
        CurrContact.Initialize
        ViewList.Initialize
        ViewList = ContactsCustListView.GetPanels(i)
        Dim temp As ListView
        temp=ViewList.Get(1)
        CurrContact = cu.FindContactsByName(ViewList.Get(1),False,False)
        ContactsCustListView.RemoveAt(i)
        'ContactsCustListView.InsertAt(i+1,CreateContactItem(CurrContact,True, ContactsCustListView.AsView.Width, 50dip), 50dip, CurrContact.Id) 'Add contact to list
    Next
End Sub
 

Attachments

  • Upload.jpg
    Upload.jpg
    400.4 KB · Views: 165

LucaMs

Expert
Licensed User
Longtime User
I have an issue in which I seem to be getting an error when running. The program closes when I try to execute line 134, and this seems to happen no matter what data type the temp variable is (I've tried object, string, list, listview). As best I can tell the list.get command is failing somehow, but I can't think of any other variations that might be causing this.

Included is a screenshot of the program taken while running. Top left is the code (problem line is the first one with debug option on), bottom left is the expanded list of contents of the ViewList variable, and right is the error I get when the program fails (which oddly references a function in the CustomListView module that I'm not even calling here).

Any help would be much appreciated! Also, code for the sub in question is here below. The problem line is temp=ViewList.Get(1)

B4X:
Sub CheckUncheckButton_CheckedChange(Checked As Boolean)
    Dim ViewList As List
    Dim ListSize As Int
    Dim CurrContact As cuContact
    ListSize = ContactsCustListView.getsize
    For i = 0 To ListSize-1
        CurrContact.Initialize
        ViewList.Initialize
        ViewList = ContactsCustListView.GetPanels(i)
        Dim temp As ListView
        temp=ViewList.Get(1)
        CurrContact = cu.FindContactsByName(ViewList.Get(1),False,False)
        ContactsCustListView.RemoveAt(i)
        'ContactsCustListView.InsertAt(i+1,CreateContactItem(CurrContact,True, ContactsCustListView.AsView.Width, 50dip), 50dip, CurrContact.Id) 'Add contact to list
    Next
End Sub


I'm not so sure, but try.

May you get a wrong error line, since you are using Rapid Debugger.
Try to Clean Project before running it.

I think the error is at line 132. Check your var types
 
Upvote 0

shaffnert03

Member
Licensed User
Longtime User
LucaMs, tried that, and have tried all sorts of data types without it working so no go so far, but thanks for the thought!

Erel, project file attached.
 

Attachments

  • Upload.zip
    23.2 KB · Views: 178
Upvote 0

shaffnert03

Member
Licensed User
Longtime User
Wait, I'm confused, I'm pulling information out of the old item before removing it from the list, how would removing it first help me? Also, the code fails on the very first execution through the loop, if I debug it hits that one line and bombs out so it's not the upper limit of the loop that's causing me problems. I think I must be misunderstanding what you're saying, can you clarify?

Alternatively, if someone can tell me how to check or uncheck the box in the custom list view via code that would work too, that's what this code is doing anyway, I just couldn't find a way to do it straight out so instead I'm removing and re-adding the line with the box properly checked.
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
Let me remove the haze of crap from your code to give you some clarity:


B4X:
For i = 0 To ListSize-1
 ViewList = ContactsCustListView.GetPanels(i)Dim temp AsListView
 ContactsCustListView.RemoveAt(i)

Next


Imagine ListSize = 2, the loop runs from 0 to 1
On the first iteration, you remove an item.
Now the size of the list is 1.
In reality at this point there are no more items to iterate on.
But your loop with run
It will try to find/remove an item that does not exist.

I suggest you take out the 2 seconds it takes to reverse the loop and give it a shot.
 
Upvote 0

shaffnert03

Member
Licensed User
Longtime User
Umm, wow, that was unnecessarily harsh. Thanks for taking the time to comment, but I'd ask that if you can't do so without being insulting you don't comment at all. I've been working in this language for less than a week and simply asked a question. If I'm wrong just tell me where I'm wrong. That is what I'm here for after all, no need for it to get rude.

To your point, I reversed the loop and the problem persisted. Furthermore, reversing the loop would remove the item I'm trying to get information from before I could get the information, defeating the purpose. Third, the loop fails on the first iteration when I step through it line by line, so what happens on any subsequent iteration is beside the point.

Finally, the point is moot because in the final code I will, at the end of the loop, be reinserting an item at the same point as the one I removed. I hadn't put that line in yet because I was testing this problem first. So yes, as it stands now the code would cause me the problem you reference once I got there. But that problem isn't one I'll actually hit given my plan, and as far as I can tell it is totally unrelated to the actual issue I posted about.
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
Umm, wow, that was unnecessarily harsh. Thanks for taking the time to comment, but I'd ask that if you can't do so without being insulting you don't comment at all. I've been working in this language for less than a week and simply asked a question. If I'm wrong just tell me where I'm wrong. That is what I'm here for after all, no need for it to get rude.
Sorry if it came off as rude. I re-read the post, I dont find it rude or insulting. Its not meant to be rude. If you dont like it, I can delete it.
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
I *guess* what you are trying to do here is:
B4X:
Dim ParentPanel as Panel
ParentPanel =ContactsCustListView.GetPanel(i)
Dim temp As lbl
temp=ParentPanel.Get(0)
CurrContact = cu.FindContactsByName(temp,False,False)
GetPanels returns an iterable list, but it doesnt seem to be a B4A list.
 
Upvote 0

shaffnert03

Member
Licensed User
Longtime User
@thedesolatesoul, no need to delete, thanks for following up, perhaps I was being overly sensitive, my apologies if so. I appreciate your sticking around to help. The label approach didn't fix it though, still bombed out on that line, no clue why.

@Erel, tried to replace the line with a version that iterated through, and also tried to just dim temp as a ListView, both still seemed to bomb out. Did it work for you? I'd used an iterablelist like that in another section of my program, but it doesn't seem to work here, is there a simpler way to get the information out?
 
Upvote 0

shaffnert03

Member
Licensed User
Longtime User
Yes, you should be able to. It's in the ImportContacts module at line 134, any insight you have would be much appreciated! When the program opens hit the menu button, chose "Import Contacts", and then click the bottom left "Uncheck All" button. That's where the error is.

Also, if you see another way to programmatically check or uncheck the box that would work for me too.
 
Last edited:
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Yes, you should be able to. It's in the ImportContacts module at line 134, any insight you have would be much appreciated! When the program opens hit the menu button, chose "Import Contacts", and then click the bottom left button. That's where the error is.

Also, if you see another way to programmatically check or uncheck the box that would work for me too.


"When the program opens hit the menu button, chose "Import Contacts", and then click the bottom left button"

I opened menu, selected left button "Import Contacs", then selected "All" and now i see my contacts (emulator, one contact only). No errors!

Maybe I should be able to add my contact to your Joe? but after importing and maintained selected my contact, I do not see how to "save"
 
Last edited:
Upvote 0

shaffnert03

Member
Licensed User
Longtime User
Sorry, after you've imported the contacts hit the bottom left button, the "Uncheck All" one. That calls the code where the error is. I should have made that clearer in my first directions.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Sorry, after you've imported the contacts hit the bottom left button, the "Uncheck All" one. That calls the code where the error is. I should have made that clearer in my first directions.

Surely you have been clear and I am hasty :rolleyes: and do not know English well.

But I would not have asked that question if ... I saw that button!

Strangely, when I load the ImportContactLayout in the Designer, the Designer indicates 320x480 scale = 1 and a black screen. I have to "widen" the Abstract Designer to see the buttons! And I do not see them running (on a 320x480-1 emulator!)

I'll try again
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I don't see this button. However I see the problem.

This sub is not part of CustomListView and it is wrong:
B4X:
Public Sub GetPanels(Index As Int) As List
   Dim p As Panel
   p = panels.Get(Index)
   Return p.GetAllViewsRecursive
End Sub

Your code should be:
B4X:
Dim p As Panel = ContactsCustListView.GetPanel(i)
 Dim temp As ListView = p.GetView(0) 'not sure that this is the correct index
 
Upvote 0

shaffnert03

Member
Licensed User
Longtime User
I hate to be so ignorant here, but how do I then get the text value out of that view? It does seem to work up to a point now, but if I use the listview as is then it gives me the "ToString" value which is "(TextView): Left=7, Top=3, Width=225, Height=69." How do I get the text value from the listview instead?

Also, Erel, are you saying that my CustomListView has a wrong sub in it? I downloaded it from http://www.b4x.com/android/forum/th...xible-list-based-on-scrollview.19567/#content, are you saying that the library there has a wrong sub in it?
 
Upvote 0
Top