I’m trying to read a text file, one line at a time, into a list view. It seems to work, I can see the first few rows fine, but as soon as I try to scroll down the list I get a error.
2014-04-28 13:58:01.468 Corona Simulator[6625:507] Runtime error
/Users/Steve/Desktop/Machinist_Calculator/charts.lua:50: bad argument #-1 to ‘newText’ (string expected, got nil)
stack traceback:
[C]: in function ‘newText’
/Users/Steve/Desktop/Machinist_Calculator/charts.lua:50: in function ‘_onRowRender’
?: in function ‘_createRow’
?: in function ‘_manageRowLifeCycle’
?: in function <?:512>
?: in function <?:218>
I’m not sure what is wrong? Here is the code:
local function onRowRender2( event ) -- Get reference to the row group local row = event.row -- Cache the row "contentWidth" and "contentHeight" because the row bounds can change as children objects are added local rowHeight = row.contentHeight local rowWidth = row.contentWidth local rowTitle = display.newText( { parent = row, text = decEquiTable[decEquiCounter], x = 0, y = 0, font = "BerlinSansFB-Reg", fontSize = 18} ) if row.index == 1 then rowTitle:setFillColor( 1 ) else rowTitle:setFillColor( 0 ) end -- Align the label left and vertically centered rowTitle.anchorX = 0 rowTitle.x = 10 rowTitle.y = rowHeight \* 0.5 decEquiCounter = decEquiCounter + 1 end function scene:create( event ) local sceneGroup = self.view isOverlay = event.params.isOverlay myData.isOverlay = isOverlay choiceTable = {} decEquiTable = {} decEquiCounter = 1 decEqui = widget.newTableView( { left = 0, --top = display.contentHeight + 10, top = 0, width = display.contentWidth, height = display.contentHeight, onRowTouch = onRowTouch2, onRowRender = onRowRender2, hideScrollBar = false, } ) sceneGroup:insert(decEqui) local path = system.pathForFile( "charts/DecEqui.txt") local file = io.open( path, "r") for line in file:lines() do decEquiTable[decEquiCounter] = line local isCategory = false local rowHeight = display.contentHeight / 6 local rowColor = { default={ 1, 1, 1 }, over={ 1, 0.5, 0, 0.2 } } local lineColor = { 0.15, 0.4, 0.729 } if ( decEquiCounter == 1 ) then isCategory = true rowColor = { default={ 0.15, 0.4, 0.729, 0.95 } } lineColor = { 1, 0, 0 } end decEqui:insertRow( { isCategory = isCategory, rowHeight = rowHeight, rowColor = rowColor, lineColor = lineColor } ) end
The text file has 169 lines, and there are no blank lines.
It seems odd I only get the error when I attempt to scroll?