bad argument #1 'newText' (string expected, got nil)

Hello

I have been recently trying to migrate from widget 1.0 to 2.0 slowly. The migration to widget 2.0 is a bit tedious. The problem is I have been getting this error

Error: bad argument #1 to ‘newText’ (string expected, got nil) 

at this part of the code

local rowText = {"sky", "ground", "floor"}   local function onRowRender( event )         local row = event.row         local rowGroup = event.view         local label = "List item "         local color = 0         --Create the row's text           local thisRowText         if rowText[row.index] ~= nil then           thisRowText = rowText[row.index]         else           thisRowText = ""         end           row.textObj = display.newText( rowGroup, thisRowText, 0, 0,native.systemFontBold, 20 ) --The error is directing here         row.textObj:setTextColor( color )         row.textObj:setReferencePoint( display.CenterLeftReferencePoint )         row.textObj.x = 90         row.textObj.y = 40         rowGroup:insert( row.textObj )                  --Create the row's arrow         row.arrow = display.newImage( "rowArrow.png",false )         row.arrow.x = rowGroup.contentWidth - row.arrow.contentWidth \* 10         row.arrow.y = rowGroup.contentHeight \* 0.5         rowGroup:insert( row.arrow )                     row.arrow2 = display.newImageRect( "blk"..row.index..".png",60,60)         row.arrow2.x = 40         row.arrow2.y = rowGroup.contentHeight \* 0.5         rowGroup:insert( row.arrow2 )        end  local function onRowTouch( event )     local row = event.row     local background = event.background     if event.phase == "press" then         print( "Pressed row: " .. row.index )         background:setFillColor( 0, 110, 233, 255 )     elseif event.phase == "release" or event.phase == "tap" then         director:changeScene("blk"..row.index)         print( "Tapped and/or Released row: " .. row.index )         background:setFillColor( 0, 110, 233, 255 )         row.reRender = true     end end -- insert rows into list (tableView widget) list = widget.newTableView     {         top = 32,         width = 320,         height = 400,     hideBackground = true,     maskFile = "mask-320x448.png",     onRowRender = onRowRender,     onRowTouch = onRowTouch,          } --Insert widgets/images into a group widgetGroup:insert( list ) widgetGroup:insert( titleBar ) --widgetGroup:insert( back ) widgetGroup:insert( titleText ) for i = 1, 3 do     list:insertRow     {         rowHeight = 80,         rowColor =         {             default = { 255, 255, 255, 0 },         },     } end end

I have been trying to interpret what the the error is saying. What is it trying to say?

 

think your problem lies in rowGroup and how you are creating the objects. I did a short test sample for reporting errors with the table view when deleting and adding rows, maybe this can help you:

[lua]

display.setStatusBar( display.HiddenStatusBar )

local widget = require( “widget” )

local list

local addButton

local deleteAllRows

– Handle row rendering

local function onRowRender( event )

   local row = event.row

   local rowTitle = display.newText( row, "List item " … row.index, 0, 0, native.systemFontBold, 16 )

   rowTitle.x = row.x - ( row.contentWidth * 0.5 ) + ( rowTitle.contentWidth * 0.5 )

   rowTitle.y = row.contentHeight * 0.5

   rowTitle:setTextColor( 0, 0, 0 )

end

– Handle row touch events

local function onRowTouch( event )

   local phase = event.phase

   local row = event.row

   local found

   if “release” == phase then

      list:deleteRow(row.index)

   end

end

– Create a tableView

list = widget.newTableView

   {

   top = 38,

   width = 320, 

   height = 448,

   onRowRender = onRowRender,

   onRowTouch = onRowTouch,

   }

– insert rows into list (tableView widget)

for i = 1, 3 do

   list:insertRow{

      height = 72,

   }

end

– Create a button for insert new rows

addButton = widget.newButton{

   left = 5,

   top = 5,

   width = 150,

   height = 30,

   label = “add row” ,

    onRelease = function()

      list:insertRow{ height = 72, }

    end

}

–create a button that deletes all rows

deleteAllRows = widget.newButton{

    label = “delete all”,

    top = 5,

    width = 150,

    height = 30,

    fontSize = 20,

    onRelease = function()

        list:deleteAllRows()

    end

    }

deleteAllRows.x = display.contentWidth - deleteAllRows.contentWidth/2 - 5

[/lua]

@borgb

Yes it did help to show all my rows, but what about the individual text, and images each row having a different image and text.

think your problem lies in rowGroup and how you are creating the objects. I did a short test sample for reporting errors with the table view when deleting and adding rows, maybe this can help you:

[lua]

display.setStatusBar( display.HiddenStatusBar )

local widget = require( “widget” )

local list

local addButton

local deleteAllRows

– Handle row rendering

local function onRowRender( event )

   local row = event.row

   local rowTitle = display.newText( row, "List item " … row.index, 0, 0, native.systemFontBold, 16 )

   rowTitle.x = row.x - ( row.contentWidth * 0.5 ) + ( rowTitle.contentWidth * 0.5 )

   rowTitle.y = row.contentHeight * 0.5

   rowTitle:setTextColor( 0, 0, 0 )

end

– Handle row touch events

local function onRowTouch( event )

   local phase = event.phase

   local row = event.row

   local found

   if “release” == phase then

      list:deleteRow(row.index)

   end

end

– Create a tableView

list = widget.newTableView

   {

   top = 38,

   width = 320, 

   height = 448,

   onRowRender = onRowRender,

   onRowTouch = onRowTouch,

   }

– insert rows into list (tableView widget)

for i = 1, 3 do

   list:insertRow{

      height = 72,

   }

end

– Create a button for insert new rows

addButton = widget.newButton{

   left = 5,

   top = 5,

   width = 150,

   height = 30,

   label = “add row” ,

    onRelease = function()

      list:insertRow{ height = 72, }

    end

}

–create a button that deletes all rows

deleteAllRows = widget.newButton{

    label = “delete all”,

    top = 5,

    width = 150,

    height = 30,

    fontSize = 20,

    onRelease = function()

        list:deleteAllRows()

    end

    }

deleteAllRows.x = display.contentWidth - deleteAllRows.contentWidth/2 - 5

[/lua]

@borgb

Yes it did help to show all my rows, but what about the individual text, and images each row having a different image and text.