ERROR: bad argument #-2 to 'insert' (proxy expected got nil) ?

Hy all!

I’m newbie of Corona. I’m trying to do an APP for my work, but I foun an error that it is incomprehensible for me.

When I run my APP, it give me the error

" Runtime error

  bad argument #-2 to ‘insert’ (proxy expected got nil)

  stack traceback:

[C]: ?

[C]: in function 'insert’

?: in function ‘insert’"

on line with " myList:insert{" .

I try to modify the code witrh the tutorial on http://coronalabs.com/blog/2014/03/04/tutorial-advanced-tableview-tactics/ , but nothing change.

I try on a Windows machine and the result is the same.

I updated with the latest stable relaese on Corona SDK, but nothing change.

I write almost all the code in the file. I left only graficals enchainments.

local storyboard = require( "storyboard" ) local scene = storyboard.newScene() local widget = require "widget" local myList, backBtn, detailScreenText storyboard.purgeAll() storyboard.removeAll() local function onRowRender( event ) print ("TEST HERE ") -- THIS DOES NOT WORK local row = event.row local id = row.index local params = event.row.params row.bg = display.newRect( 0, 0, display.contentWidth, 60 ) row.bg.anchorX = 0 row.bg.anchorY = 0 row.bg:setFillColor( 1, 1, 1 ) row:insert( row.bg ) if ( event.row.params ) then row.nameText = display.newText( params.id, 12, 0, native.systemFontBold, 18 ) row.nameText.anchorX = 0 row.nameText.anchorY = 0.5 row.nameText:setFillColor( 0 ) row.nameText.y = 20 row.nameText.x = 42 row.phoneText = display.newText( params.title, 12, 0, native.systemFont, 18 ) row.phoneText.anchorX = 0 row.phoneText.anchorY = 0.5 row.phoneText:setFillColor( 0.5 ) row.phoneText.y = 40 row.phoneText.x = 42 row.rightArrow = display.newImageRect( params.image, 15 , 40, 40 ) row.rightArrow.x = display.contentWidth - 20 row.rightArrow.y = row.height / 2 row:insert( row.nameText ) row:insert( row.phoneText ) row:insert( row.rightArrow ) end return true end local function networkListener( event ) local message = {} if ( event.isError ) then print( "Network error!") else myNewData = event.response local users = xml:loadFile( myNewData, "internal" ) for i=1,#users.child do message[i] = users.child[i] end myList:deleteAllRows() for i=1,#message do myData[i] = { title = message[i].child[2].value, subtitle = message[i].child[4].value, image = "coffee1.png", id=message[i].child[3].value, recid=message[i].child[1].value } print ("msg n. " .. myData[i].id) -- THIS WORKS myList:insert{ rowHeight = 60, isCategory = false, rowColor = { 1, 1, 1 }, lineColor = { 0.90, 0.90, 0.90 }, params = { title = myData[i].title, subtitle = myData[i].subtitle, image = myData[i].image, id = myData[i].id, recid = myData[i].recid } } end end return #message end local button1Press = function( event ) local body = "artid=" .. log1 .. "&sess=" .. parameters.sess local params = {} params.body = body TotArray = 0 print ("params " .. body) local sendto = "http://localhost/xmlserver.php" TotArray = network.request( sendto , "POST", networkListener, params ) -- return resultset end function scene:enterScene( event ) local group = self.view local button1 = widget.newButton { defaultFile = "icon-find.png", overFile = "icon-find.png", label = "", emboss = true, left = 276, top = 54, onPress = button1Press, onRelease = button1Release, } group:insert(button1) findtxt = native.newTextField( 160, 80, 220, tHeight ) log1 = findtxt.text findtxt.isEditable = true findtxt:addEventListener( "userInput", textListener ) group:insert(findtxt) local txt2 = display.newText( "Find", 0, 0, native.systemFont, 12 ) txt2:setFillColor( 1, 0.2 , 0 ) txt2.x, txt2.y = 30, 80 group:insert(txt2) backBtn = widget.newButton{ defaultFile = "backButton.png", overFile = "backButton\_over.png", onRelease = backBtnRelease } backBtn.x = 30 backBtn.y = 40 group:insert(backBtn) myList = widget.newTableView { -- id=tabellaRisultati, onRowTouch=listButtonRelease, top=120, left=100, backgroundColor={ 255, 255, 255 } } group:insert(myList) return group end scene:addEventListener("enterScene", scene) function scene:willEnterScene( event ) findtxt.text = "" log1 = findtxt.text end scene:addEventListener( "willEnterScene", scene ) return scene

Hi @zemal,

This is a syntax error. It appears that you’re trying to “insert a tableView” into an existing tableView. What is the scenario you’re trying to accomplish?

Thanks,

Brent

Hy!

Thanks for the reply.

I forgot a little piece where I declare the “widget.newTableView” before insert in the group. I add it.

Hi @zemal,

So is your issue resolved? Or is something still not working?

Thanks,

Brent

No, nothing resolved. I forgot only a declaration coping my code here.

I explane what it does.

There are a field text where the user type something. There is a listener that after 3 words lunch the button1press.

Alternately the user can press the button1 manually. This lunch the a request via XML to a my php server page.

The result is stored by networkListener function on myData array.

Here all works great. I can print my data on debug console and it works.

The results must be insered on a tableview already declared.

As soon I put an insert, the debug console gives me the error.

I try to declare the tableviewat the top of the file, but nothing change.

I try to declare the tableview when I need for it, but nothing change.

Please help!

Thanks

Hi @zemal,

The problem may be this: when you declare the tableView, you’re setting an “id” value of “tabellaRisultati”. However, do you declare this variable “tabellaRisultati” anywhere? If this variable is undefined, Lua will present an error, because it doesn’t recognize this variable.

Did you intend to set this as a string value? For example:

[lua]

      id = “tabellaRisultati”,

[/lua]

Take care,

Brent

Thank you, but this isn’t a problem.

I commented that line and the error persist.

http://docs.coronalabs.com/api/library/widget/newTableView.html

By the way, according to documentation, the “id” is “An optional identification string to assign to the table view” and so I don’t think I must declare it before. It is an optional name that you can assign to the tableview.

Any other ideas?

Thanks

Hi @zemal,

Can you please post your most current code, containing the line which is giving you an error? I need to look at what you currently have.

Thanks,

Brent

I updated my initial post. I commented the line 122 as I sayd.

This is I currently have: the compiler still says that the error is on line 61 myList:insert and I don’t know why.

Hi @zemal,

This is the same syntax error as in the beginning. You are trying to insert a table into the tableView. You must insert display objects into specific tableView rows. Please study the documentation further to see how:

http://docs.coronalabs.com/api/library/widget/newTableView.html

Take care,

Brent

WOW! What a wonderful comment! You will be in all my app credits! I will look the documentation!!

 … but … I get the same error with this code:

local widget = require ("widget") local myList = widget.newTableView { } myList:insert{ }

… and so it is possible that the problem is could be another. I’m a newbie, not an idiot.

Hi @zemal,

It’s a common misunderstanding. You just need to obey the syntax for :insert:

http://docs.coronalabs.com/api/type/GroupObject/insert.html

For tableViews, each row is a display group, so you must insert display objects into a row. You can’t insert tables, and saying…

[lua]

myList:insert{}

[/lua]

…says that you’re trying to insert a table. This is not allowed.

Take care,

Brent

Hi @zemal,

This is a syntax error. It appears that you’re trying to “insert a tableView” into an existing tableView. What is the scenario you’re trying to accomplish?

Thanks,

Brent

Hy!

Thanks for the reply.

I forgot a little piece where I declare the “widget.newTableView” before insert in the group. I add it.

Hi @zemal,

So is your issue resolved? Or is something still not working?

Thanks,

Brent

No, nothing resolved. I forgot only a declaration coping my code here.

I explane what it does.

There are a field text where the user type something. There is a listener that after 3 words lunch the button1press.

Alternately the user can press the button1 manually. This lunch the a request via XML to a my php server page.

The result is stored by networkListener function on myData array.

Here all works great. I can print my data on debug console and it works.

The results must be insered on a tableview already declared.

As soon I put an insert, the debug console gives me the error.

I try to declare the tableviewat the top of the file, but nothing change.

I try to declare the tableview when I need for it, but nothing change.

Please help!

Thanks

Hi @zemal,

The problem may be this: when you declare the tableView, you’re setting an “id” value of “tabellaRisultati”. However, do you declare this variable “tabellaRisultati” anywhere? If this variable is undefined, Lua will present an error, because it doesn’t recognize this variable.

Did you intend to set this as a string value? For example:

[lua]

      id = “tabellaRisultati”,

[/lua]

Take care,

Brent

Thank you, but this isn’t a problem.

I commented that line and the error persist.

http://docs.coronalabs.com/api/library/widget/newTableView.html

By the way, according to documentation, the “id” is “An optional identification string to assign to the table view” and so I don’t think I must declare it before. It is an optional name that you can assign to the tableview.

Any other ideas?

Thanks