Runtime Error in Corona

See the attached file.

Sometimes it show this type of error in simulator but its working fine in devices.

What will be the possible reason for this problem?

gamedata.lua file(error occur in this file)

local json = require(“json”)

local gameData = {}

local fileName = “gameData1.json”   

function gameData.setGameData()

local gameData

local path = system.pathForFile( fileName, system.DocumentsDirectory )

local file = io.open( path, “r” ) 

if(file == nil) then

print(“first run”)

local path = system.pathForFile( fileName, system.ResourceDirectory )   

local file = io.open( path, “r” )

local readData = file:read( “*a” )

gameData = json.decode(readData)

io.close( file )

file = nil

local path = system.pathForFile( fileName, system.DocumentsDirectory )

local file = io.open( path, “w” ) 

file:write( readData ) 

io.close( file )

file = nil 

end

local path = system.pathForFile( fileName, system.DocumentsDirectory )

local file = io.open( path, “r” )

local readData = file:read( “*a” )

local gameData = json.decode(readData)

io.close( file )

file = nil

return gameData

end

function gameData.getGameData()

local path = system.pathForFile(fileName, system.DocumentsDirectory )

local file = io.open( path, “r” )

local readData = file:read( “*a” )

local gameData = json.decode(readData)

io.close( file )

file = nil

return gameData

end

function gameData.saveGameData(gameData)

local saveData = json.encode(gameData) –error occur here

local path = system.pathForFile( fileName, system.DocumentsDirectory ) 

local file = io.open( path, “w” ) 

file:write( saveData )  

io.close( file )

file = nil 

return true 

end

return gameData  

What is line 52?  Have you verified that the file name is really there and that you can open it?

Rob

Line 52 is       file:write( saveData )

File name is correct, everything is working fine and the probability of this error is only 30%(approx) and it occur only in simulator not in devices.

What is line 52?  Have you verified that the file name is really there and that you can open it?

Rob

Line 52 is       file:write( saveData )

File name is correct, everything is working fine and the probability of this error is only 30%(approx) and it occur only in simulator not in devices.