Hello! I’m new to developing with Corona/Lua and i’m trying to develop a list view using an xml that’s been exported from a magento shop. I used the tutorial on this page. When loading the image from a local folder in the list view it works fine but when i try to insert a downloaded image using loadRemoteImage i get an error saying
[text]ERROR: table expected. If this is a function call, you might have used ‘.’ instead of ‘:’
stack traceback:
[C]: ?
[C]: in function ‘insert’[/text]
I tried to download the remote image while reading the xml file and then use the image again with newImage in the listview but it won’t show. When i comment out the loadRemoteImage it works fine.
My code;
[lua]local tableView = require(“tableView”)
local ui = require(“ui”)
local xml = require(“xmlSimple”).newParser()
local parsedXml = xml:loadFile(“file.xml”, base)
local data = {}
function removecdata(val)
local i = 1
local cdata_start,cdata_start2 = val:find(" if (cdata_start) then
abs = i+cdata_start2
cdata_end,cdata_end2 = val:find("%]%]>",i)
i = cdata_end2
val = val:sub(abs,cdata_end-1)
end
return val
end
–XML to ARRAY
for y = 1, 10, 1 do
data[y] = {}
data[y].title = removecdata(parsedXml.rss.channel.item[y].title:value())
data[y].subtitle = removecdata(parsedXml.rss.channel.item[y].description:value())
data[y].link = removecdata(parsedXml.rss.channel.item[y].link:value())
data[y].image = removecdata(parsedXml.rss.channel.item[y]:children()[9]:value())
data[y].imgTitle = “img”…y…".jpg"
–display.loadRemoteImage(data[y].image, “GET”, networkListener, data[y].imgTitle, system.DocumentsDirectory)
end
local function networkListener( event )
if ( event.isError ) then
print ( “Network error - download failed” )
else
event.target.alpha = 0
transition.to( event.target, { alpha = 1.0 } )
end
print ( "RESPONSE: " … event.response )
end
local g = display.newGroup()
– ARRAY to TABLE
local myList = tableView.newList{
data=data,
default=“listItemBg.png”,
backgroundColor={255,2552,255},
callback = function( row )
–local img = display.newImage(row.imgTitle, system.DocumentsDirectory,0,0)
local img = display.loadRemoteImage(row.image, “GET”, networkListener, row.imgTitle, system.DocumentsDirectory)
g:insert(img)
img.x = math.floor(img.width*0.5 + 6)
img.y = math.floor(img.height*0.5)
local title = display.newText( row.title, 0, 0, native.systemFontBold, 14 )
title:setTextColor(0,0,0)
g:insert(title)
title.x = title.width*0.5 + img.width + 6
title.y = 30
local subtitle = display.newText( row.subtitle, 0, 0, native.systemFont, 12 )
subtitle:setTextColor(80,80,80)
g:insert(subtitle)
subtitle.x = subtitle.width*0.5 + img.width + 6
subtitle.y = title.y + title.height + 6
return g
end
}[/lua]
I hope someone can help me…
Thanks in advance! [import]uid: 199479 topic_id: 33671 reply_id: 333671[/import]