In the main.lua file of my app, i call a function that loads and decodes a json file. The function looks like this:
local function loadJsonFile( filename )
local path = system.pathForFile (filename, system.DocumentsDirectory)
local contents = ""
local fileTable = {}
local file = io.open ( path, "r" )
if file then
local contents = file:read ( "\*a" )
fileTable = json.decode ( contents )
io.close ( file )
print ( "loaded" )
return fileTable
end
return nil
end
In main.lua i call this function like this:
local gameSettings = filefunctions.loadJsonFile( "gamesettings.json" )
My gamesettings.json file is located in the documents directory of the projects sandbox. After loading and decoding the json file i set some variables like this:
storyboard.gameState.currentscore = gameSettings.CurrentScore
I do this for each json file in the documents directory ( 3 files). This works perfectly in the simulator ( Windows 7) . When i build for android, install the app on an android device and start it, i get the following runtime error:
…\AppDevelopment\beta\04\EVOLUTION\betaVersion6_0\main.lua:25: attempt to index local gameSettings (a nil value)
Line 25 contains: storyboard.gameState.currentscore = gameSettings.CurrentScore
It just means, opening and decoding the file has failed. My problem is, i don´t understand why - the thing is, everything runs perfectly in the simulator.
Cay anyone help? What is the correct way to handle files on android devices?
[import]uid: 196206 topic_id: 36846 reply_id: 336846[/import]