Hi I am new in Corona SDK and Lua. now I am developing a project that having a database. and I have encountered a problem in my displaying a list. I am using TableView for the listing of the (songs)data.
I got this error, and i don’t know why it came.
[bash]
Runtime error
…\singingidol\filereader\singingidolmenu\director.lua:1092: attempt to
call method ‘insert’ (a nil value)
stack traceback:
[C]: in function ‘insert’
…\singingidol\filereader\singingidolmenu\director.lua:1092: in functio
n ‘changeScene’
Director ERROR: Failed to execute new( params ) function on ‘freeplay’.
bad argument #1 to ‘_newText’ (string expected, got nil)
[/bash]
i got this when I click the ‘ARTIST’ category and click one of ARTIST to display all the artist songs.
this is my whole code …
play.lua
module(..., package.seeall)
require "sqlite3"
local tableView = require("tableView")
local ui = require("ui")
local sam\_ui = require("sam\_ui")
function new()
display.setStatusBar( display.HiddenStatusBar )
local screenOffsetW, screenOffsetH = display.contentWidth - display.viewableContentWidth, display.contentHeight - display.viewableContentHeight
local myList, detailScreenText
local back\_button
local path = system.pathForFile( "singingIdol.db", system.DocumentsDirectory )
local db = sqlite3.open( path )
local songs\_screen = display.newGroup()
local difficulty\_screen = display.newGroup()
print (\_W)
local sBackground = display.newImageRect("bgsprite.jpg", display.contentWidth, display.contentHeight);
sBackground:setReferencePoint(display.CenterReferencePoint);
sBackground.x = display.contentWidth/2; sBackground.y = display.contentHeight/2;
sBackground.alpha = .4
songs\_screen:insert(sBackground)
-------------------
-- filtering
-------------------
local filterBy
local subFilterBy
local subFilterByValue
for row in db:nrows("SELECT \* FROM freeplay WHERE id=1") do
filterBy = row.freeplay
end
for row in db:nrows("SELECT \* FROM tempt\_sub WHERE id=1") do
subFilterBy = row.sub
subFilterByValue = row.val
end
print (filterBy)
print (subFilterBy)
print (subFilterByValue)
local count = 1
local data = {}
local animate = function(event)
back\_button.rotation = back\_button.rotation + 1
end
local reloadFreeplay = function()
Runtime:removeEventListener("enterFrame", animate)
Runtime:removeEventListener("enterFrame", move)
director:changeScene ("freeplay\_reloader")
print ("reloaded!")
end
local getFreeSong = function()
for row in db:nrows("SELECT song.id as id, song.title as song, artist.name as artist, genre.name as genre, album.title as album FROM song, artist, genre, album WHERE song.artist\_id = artist.id AND song.genre\_id = genre.id AND song.album\_id = album.id AND song.price = 0") do
data[count] = {}
data[count].song = row.song
data[count].artist = row.artist
data[count].genre = row.genre
data[count].album = row.album
count = count + 1
end
end
local getAllSong = function()
for row in db:nrows("SELECT song.id as id, song.title as song, artist.name as artist, genre.name as genre, album.title as album FROM song, artist, genre, album WHERE song.artist\_id = artist.id AND song.genre\_id = genre.id AND song.album\_id = album.id ORDER BY song.title") do
data[count] = {}
data[count].song = row.song
data[count].artist = row.artist
data[count].genre = row.genre
data[count].album = row.album
count = count + 1
end
end
local getNewSong = function()
for row in db:nrows("SELECT song.id as id, song.title as song, artist.name as artist, genre.name as genre, album.title as album FROM song, artist, genre, album WHERE song.artist\_id = artist.id AND song.genre\_id = genre.id AND song.album\_id = album.id ORDER BY song.id DESC") do
data[count] = {}
data[count].song = row.song
data[count].artist = row.artist
data[count].genre = row.genre
data[count].album = row.album
count = count + 1
end
end
local getArtist = function()
for row in db:nrows("SELECT DISTINCT artist.name as name FROM song, artist WHERE song.artist\_id=artist.id ") do
data[count] = {}
data[count].name = row.name
count = count + 1
end
end
local getGenre = function()
for row in db:nrows("SELECT DISTINCT genre.name as name FROM song, genre WHERE song.genre\_id=genre.id ") do
data[count] = {}
data[count].name = row.name
count = count + 1
end
end
local getSongByGenre = function()
for row in db:nrows("SELECT song.id as id, song.title as song, artist.name as artist, genre.name as genre, album.title as album FROM song, artist, genre, album WHERE song.artist\_id = artist.id AND song.genre\_id = genre.id AND song.album\_id = album.id AND genre.name='".. subFilterByValue .."' order by song.title") do
data[count] = {}
data[count].song = row.song
data[count].artist = row.artist
data[count].genre = row.genre
data[count].album = row.album
count = count + 1
end
end
local getSongByArtist = function()
for row in db:nrows("SELECT song.id as id, song.title as song, artist.name as artist, genre.name as genre, album.title as album FROM song, artist, genre, album WHERE song.artist\_id = artist.id AND song.genre\_id = genre.id AND song.album\_id = album.id AND artist.name='".. subFilterByValue .."' order by song.title") do
data[count] = {}
data[count].song = row.song
data[count].artist = row.artist
data[count].genre = row.genre
data[count].album = row.album
count = count + 1
end
end
print (data)
if filterBy == "ALL" and subFilterBy == nil and subFilterByValue == nil then
print ("true all")
getAllSong()
elseif filterBy == "NEW" and subFilterBy == nil and subFilterByValue == nil then
print ("true new")
getNewSong()
elseif filterBy == "FREE" and subFilterBy == nil and subFilterByValue == nil then
print ("true free")
getFreeSong()
elseif filterBy == "ARTIST" and subFilterBy == nil and subFilterByValue == nil then
print ("true artist")
getArtist()
elseif filterBy == "GENRE" and subFilterBy == nil and subFilterByValue == nil then
print ("true genre")
getGenre()
elseif subFilterByValue and subFilterBy == "GENRE" and filterBy == "GENRE" then
print ("sub genre true"..subFilterBy.." "..filterBy.." "..subFilterByValue)
getSongByGenre()
elseif subFilterByValue and subFilterBy == "ARTIST" and filterBy == "ARTIST" then
print ("sub artist true"..subFilterBy.." "..filterBy.." "..subFilterByValue)
print (subFilterByValue)
local data = {}
getSongByArtist()
--getSongByGenre()
end
------------------
function listButtonRelease( event )
if event.phase == "ended" then
if filterBy == "ALL" or filterBy == "NEW" or filterBy == "FREE" then
print (data[event.target.id].song)
end
if filterBy == "GENRE" then
print ("genre")
print (data[event.target.id].name)
local updateSub = [[UPDATE tempt\_sub SET sub="]] .. filterBy .. [[", val="]].. data[event.target.id].name ..[[" WHERE id=1;]]
db:exec( updateSub )
reloadFreeplay()
elseif filterBy == "ARTIST" then
print ("artist")
print (data[event.target.id].name)
local updateSub = [[UPDATE tempt\_sub SET sub="]] .. filterBy .. [[", val="]].. data[event.target.id].name ..[[" WHERE id=1;]]
db:exec( updateSub )
reloadFreeplay()
end
end
end
local onButtonTouch = function(event)
print (event.target.id)
local updateFreePlay = [[UPDATE freeplay SET freeplay="]] .. event.target.id .. [[" WHERE id=1;]]
print (updateFreePlay)
db:exec( updateFreePlay )
local deleteTempt\_sub =[[UPDATE tempt\_sub SET sub=NULL, val=NULL WHERE id=1;]]
db:exec( deleteTempt\_sub )
reloadFreeplay()
end
local backBtnRelease = function( event )
print("back button released")
Runtime:removeEventListener("enterFrame", animate)
Runtime:removeEventListener("enterFrame", move)
transition.to(myList, {time=400, x=0, transition=easing.outExpo })
transition.to(difficulty\_screen, {time=400, x=display.contentWidth, transition=easing.outExpo })
director:changeScene( "menu", "fade")
end
local topBoundary = display.screenOriginY + 40
local bottomBoundary = display.screenOriginY + 0
back\_button = ui.newButton{
defaultSrc = "back.png",
defaultX = 100,
defaultY = 100,
overSrc = "back\_down.png",
overX = 100,
overY = 100,
onEvent = backBtnRelease,
id = "Back",
text = "",
font = "Helvetica",
textColor = { 255, 255, 255, 255 },
size = 16,
emboss = false
}
back\_button.x = 432
back\_button.y = 273
transition.from(back\_button, { time=1000, delay=100, x = 540, transition=easing.outExpo} )
Runtime:addEventListener("enterFrame",animate)
--------------------
-- list view
--------------------
myList = tableView.newList{
data=data,
default="listItemBg.png",
over="listItemBg\_over.png",
onRelease=listButtonRelease,
top=topBoundary,
bottom=bottomBoundary,
callback=function(row)
local song\_info = display.newGroup()
if filterBy == "ARTIST" or filterBy == "GENRE" and subFilterBy == nil then
local sArtist = display.newText( row.name, 0, 0, native.systemFontBold, 20 )
sArtist:setTextColor(25,200,200)
sArtist:setReferencePoint(display.TopLeftReferencePoint);
sArtist.x = 10; sArtist.y = 20
song\_info:insert(sArtist)
elseif filterBy == "NEW" or filterBy == "ALL" or filterBy == "FREE" and subFilterBy == nil then
local sTitle = display.newText( row.song, 0, 0, native.systemFontBold, 17 )
sTitle:setTextColor(25,200,200)
sTitle:setReferencePoint(display.TopLeftReferencePoint);
sTitle.x = 10; sTitle.y = 15
song\_info:insert(sTitle)
local sArtist = display.newText( "by: "..row.artist.." ("..row.genre..")", 0, 0, native.systemFont, 15 )
sArtist:setTextColor(255,255,255)
sArtist:setReferencePoint(display.TopLeftReferencePoint);
sArtist.x = 10; sArtist.y = 40
song\_info:insert(sArtist)
end
print ("----------------------")
print (subFilterBy)
print (filterBy)
print (subFilterByValue)
if subFilterBy == "GENRE" and filterBy == "GENRE" and subFilterByValue then
local sTitle = display.newText( row.song, 0, 0, native.systemFontBold, 17 )
sTitle:setTextColor(25,200,200)
sTitle:setReferencePoint(display.TopLeftReferencePoint);
sTitle.x = 10; sTitle.y = 15
song\_info:insert(sTitle)
local sArtist = display.newText( "by: "..row.artist.." ("..row.genre..")", 0, 0, native.systemFont, 15 )
sArtist:setTextColor(255,255,255)
sArtist:setReferencePoint(display.TopLeftReferencePoint);
sArtist.x = 10; sArtist.y = 40
song\_info:insert(sArtist)
end
if subFilterByValue and subFilterBy == "ARTIST" and filterBy == "ARTIST" then
print ('oooooooooooooooooooooooooooo')
end
return song\_info
end
}
songs\_screen:insert(myList)
transition.from(myList, {time=400, delay=500, alpha=0, x=-385, transition=easing.outExpo })
-------------------------
-- nav Button
-------------------------
local navBar = display.newImage("navBar.png", 0, 0, true)
navBar.y = 20
transition.from(navBar, {time=400, delay=100,y=-25, transition=easing.outExpo })
songs\_screen:insert(navBar)
local navHeader = display.newText("Select a Track", 0, 0, native.systemFontBold, 16)
navHeader:setTextColor(255, 255, 255)
navHeader.x = display.contentWidth/2; navHeader.y = 20
transition.from(navHeader, {time=400, delay=100,y=-25, transition=easing.outExpo })
songs\_screen:insert(navHeader)
local menuButton = {}
button\_text = {"FREE", "NEW", "ALL", "ARTIST", "GENRE"}
menuX = 48
for i=1, 5 do
menuButton[i] = sam\_ui.newButton{
default = "navButton\_default.png",
over = "navButton\_tap.png",
text = button\_text[i],
onRelease = onButtonTouch,
size = 14
}
menuButton[i].x = menuX
menuButton[i].y = (display.screenOriginY + menuButton[i].height\*1.5)
transition.from(menuButton[i], {time=400, delay=100, x=menuX+480, transition=easing.outExpo })
menuX = menuX + 96
menuButton[i].id = button\_text[i]
songs\_screen:insert(menuButton[i])
end
return songs\_screen
end
I get the error when i call this function in my code … getSongByArtist()
i have tried if it will go to myList, i put print ('oooooooooooooooooooooooooooo'), but it not go there.
i tried also to remove the contents of my function getSongByArtist()
i remove this lines:
data[count] = {}
data[count].song = row.song
data[count].artist = row.artist
data[count].genre = row.genre
data[count].album = row.album
and the error is gone but the list is empty…
do anyone have an idea on how to handle my case?
thanks in advance … [import]uid: 142834 topic_id: 26322 reply_id: 326322[/import]