Bad argument #1 to 'lower'(string expected, got nil)

How to fix this error?

here is my code

[lua]

    gameData = getQuestions.loadSelectedQuestions(selected_category)    
    questions = (gameData[“questions”])
    answer = string.lower(gameData[“answer”])
    answerOrig = answer

    local quesPos = halfW
    local value = actualW - quesPos -10
    local border = 5

    local options = {

        text= questions,
        x = 0,
        y = 0,
        width = value - border*2,
        font = native.systemFont,
        fontSize = 30,

    }    

    local gameQuestion1 = display.newText(questions, 0,0, native.systemFont, 50)
    print(“TEST”,gameData [“answer”])

    gameQuestion1.x = halfW ;  gameQuestion1.y = halfH - 250
    gameQuestion1:setFillColor( 0 )
     quesGroup:insert(gameQuestion1)

[/lua]


Here is the code for the lua file where i see the error occur in the corona CMD simulator output

[lua]

local sqlite = require ( “sqlite3” )
local myData = require ( “myData” )

local M = {}

local function loadSelectedQuestions(category)
    local path = system.pathForFile (“Orc.sqlite” , system.DocumentsDirectory)
    local db = sqlite.open(path)
    
    local myTable = {}
    local result = {}
    local sql

    local tblName    

    
local gameCat
    gameCat = myData.gameCat
    
print ( “selected cat -->”…gameCat  )
    
–    print ( "question ID "… qID )

local ques_no = myData.categories[gameCat].ques_no
    print(ques_no)
    
     sql = “SELECT * FROM gameQuestions WHERE question_category = '” …gameCat…"’" … " AND ques_no = ‘"… ques_no …"’ ;"
     print(sql)

for row in db:nrows(sql) do
        myTable =  row
end
    
db:close()
    
    result = myTable

    print ("query result: ", result.ques_no )
    --print (myTable.img_Path)

    return result
        
    
end

M.loadSelectedQuestions = loadSelectedQuestions

return M

[/lua]

i can’t seem to find the source of the error. Please Help

In your code, you only posted one place you’re calling string.lower().  So apparently at that point: gameData[“answer”] is nil.  You need to verify the contents of gameData.  This tutorial can help you print the contents of your gameData table:

http://coronalabs.com/blog/2014/09/02/tutorial-printing-table-contents/

Rob

In your code, you only posted one place you’re calling string.lower().  So apparently at that point: gameData[“answer”] is nil.  You need to verify the contents of gameData.  This tutorial can help you print the contents of your gameData table:

http://coronalabs.com/blog/2014/09/02/tutorial-printing-table-contents/

Rob