prokli Active Member Licensed User Longtime User Jul 29, 2014 #1 I need help with an quite simple looking piece of code! This line always fails " uplTiFiles.RemoveAt(0)" as shown in example next. I am very confused because first Log() shows a list keeping up to 40 file names and second Log() shows the first file in list. So why is it not possible to remove this file from list??? Declaration in Service module Sub Process_Globals Private uplTiFiles As List End Sub somewhere I do this in a service module: uplTiFiles = File.ListFiles("system/app") and inside a timer I do this Send_File(uplTiFiles.Get(0)) Log(uplTiFiles) Log("removing file from list: " & uplTiFiles.Get(0)) 'remove from list to avoid sending it again uplTiFiles.RemoveAt(0) ' THIS ALWAYS FAILS!!
I need help with an quite simple looking piece of code! This line always fails " uplTiFiles.RemoveAt(0)" as shown in example next. I am very confused because first Log() shows a list keeping up to 40 file names and second Log() shows the first file in list. So why is it not possible to remove this file from list??? Declaration in Service module Sub Process_Globals Private uplTiFiles As List End Sub somewhere I do this in a service module: uplTiFiles = File.ListFiles("system/app") and inside a timer I do this Send_File(uplTiFiles.Get(0)) Log(uplTiFiles) Log("removing file from list: " & uplTiFiles.Get(0)) 'remove from list to avoid sending it again uplTiFiles.RemoveAt(0) ' THIS ALWAYS FAILS!!
RandomCoder Well-Known Member Licensed User Longtime User Jul 29, 2014 #3 I could be wrong, but shouldn't you prefix uplTiFiles with the name of the service module when called from outside of the service it was declared? Upvote 0
I could be wrong, but shouldn't you prefix uplTiFiles with the name of the service module when called from outside of the service it was declared?
sirjo66 Well-Known Member Licensed User Longtime User Jul 29, 2014 #4 The error is because the File.ListFiles method return a "read only list", so you can't change it You need to get the list by File.ListFiles, than copy this list in another "normal" list, so then you can delete each item from this list Sergio Upvote 0
The error is because the File.ListFiles method return a "read only list", so you can't change it You need to get the list by File.ListFiles, than copy this list in another "normal" list, so then you can delete each item from this list Sergio
prokli Active Member Licensed User Longtime User Jul 30, 2014 #5 Thanks to all! I get the error message: java.lang.UnsupportedOperationException followed by a lot more lines of error code @sirjo66: I am not sure what you are telling me! What is a "normal" list? I created a additional list as shown next: Dim oList As List and I assigned this list according to: uplTiFiles = File.ListFiles("system/app") oList = uplTiFiles Result: I get the same error message So any further idea????? Upvote 0
Thanks to all! I get the error message: java.lang.UnsupportedOperationException followed by a lot more lines of error code @sirjo66: I am not sure what you are telling me! What is a "normal" list? I created a additional list as shown next: Dim oList As List and I assigned this list according to: uplTiFiles = File.ListFiles("system/app") oList = uplTiFiles Result: I get the same error message So any further idea?????
prokli Active Member Licensed User Longtime User Jul 30, 2014 #6 Attached image of complete error message! Attachments list problem.png 32.7 KB · Views: 517 Upvote 0
thedesolatesoul Expert Licensed User Longtime User Jul 30, 2014 #7 You can use Code: Copy uplTiFiles.AddAll(File.ListFiles("system/app")) Upvote 0
prokli Active Member Licensed User Longtime User Jul 30, 2014 #8 Okay, I found the solution of my problem: See link: http://www.b4x.com/android/forum/threads/list-removeat-error.7194/ Unfortunately I assigned the second local list (oList) instead of adding it. Pretty ugly behavior! Upvote 0
Okay, I found the solution of my problem: See link: http://www.b4x.com/android/forum/threads/list-removeat-error.7194/ Unfortunately I assigned the second local list (oList) instead of adding it. Pretty ugly behavior!
prokli Active Member Licensed User Longtime User Jul 30, 2014 #9 @thedesolatesoul found the solution of my problem after a further Long reserach Thx Upvote 0