After 2 days of bafflement, I'm asking for fresh eyes.
I'm exporting data to a CSV file, but it seems to be losing the last few lines of the data.
There are 190 rows of data, but I'm only seeing 170 in the resulting file. The last line in the file is incomplete (missing part of a value in a column, and the rest of the columns in that row).
I've checked the data, but it looks fine - no weird characters, no delimiters, no line feeds.
And I've tried this on 2 different devices with 2 different Android versions - same result. I even switched from using StringUtils.saveCSV2 to using CSVParser - same result.
My logging shows that the list I'm creating and exporting does contain all 190 items.
The only other clue I have is that the CSV file is apparently encoded as "Windows 1252: Western European" instead of the UTF-8 I expected, but that may be a consequence of reading the file off the connected device using Windows?
Here's the export code:
...and the last few lines of the CSV file come out as:
So, the final column value is "false", but truncated to "fa". And the last 18 rows are missing.
Any idea what's going on here? Thanks!
I'm exporting data to a CSV file, but it seems to be losing the last few lines of the data.
There are 190 rows of data, but I'm only seeing 170 in the resulting file. The last line in the file is incomplete (missing part of a value in a column, and the rest of the columns in that row).
I've checked the data, but it looks fine - no weird characters, no delimiters, no line feeds.
And I've tried this on 2 different devices with 2 different Android versions - same result. I even switched from using StringUtils.saveCSV2 to using CSVParser - same result.
My logging shows that the list I'm creating and exporting does contain all 190 items.
The only other clue I have is that the CSV file is apparently encoded as "Windows 1252: Western European" instead of the UTF-8 I expected, but that may be a consequence of reading the file off the connected device using Windows?
Here's the export code:
B4X:
Sub exportListToFile As String
Dim headerList As List
headerList.Initialize2(Array As String("Name", "Quantity","Needed" ,"Order in list", "Note", _
"Group", "Group position", "Order in group", "Crossed out"))
Dim itemList As List
itemList.Initialize
For Each tempItem As shopItem In currentShopList.items
itemList.Add(buildExportItem(tempItem))
Next
Dim strippedName As String = _
stripToAllowedCharacters(currentShopList.name, ALLOWED_FILENAME_CHARACTERS) & ".csv"
Dim su As StringUtils
su.SaveCSV2(importExportDir, strippedName, SEPARATOR_CHAR, itemList, headerList)
Return strippedName
End Sub
Sub buildExportItem(tempItem As shopItem) As String()
Dim stringArray(9) As String
stringArray(0) = tempItem.name
stringArray(1) = tempItem.quantity
stringArray(2) = tempItem.needed
stringArray(3) = tempItem.manualIndex + 1
stringArray(4) = tempItem.note
stringArray(5) = getGroupNameFromID(tempItem.groupID)
stringArray(6) = getIndexOfGroupID(tempItem.groupID) + 1
stringArray(7) = tempItem.manualGroupIndex + 1
stringArray(8) = tempItem.crossedOut
Return stringArray
End Sub
...and the last few lines of the CSV file come out as:
B4X:
tortillas: corn small,2,false,152,,cans & sauces,6,29,false
vacuum bags S-bag,5,false,153,Electrolux/Philips,Cleaning,9,15,false
vanilla extract,1,false,154,,baking,5,17,false
venison,2,false,155,,Meat,2,5,fa
So, the final column value is "false", but truncated to "fa". And the last 18 rows are missing.
Any idea what's going on here? Thanks!