Hi…I’m working on 2 os (osX and windows 7) at the same project.
I added at my project a db made by sqlite3 and on OsX the project runs. But when i work on windows the project show me an error during creation of database.
Error : Attempt to index local fileSource (a nil value)
Why that? What change between 2 os?
I allegate the code:
local function setUpDatabase(dbName) local path = system.pathForFile( dbName, system.DocumentsDirectory ) local file = io.open( path, "r" ) if ( file == nil ) then -- copy the database file if doesn't exist local pathSource = system.pathForFile( dbName, system.ResourceDirectory ) local fileSource = io.open( pathSource, "r" ) local contentsSource = fileSource:read( "\*a" ) local pathDest = system.pathForFile( dbName, system.DocumentsDirectory ) local fileDest = io.open( pathDest, "w" ) fileDest:write( contentsSource ) io.close( fileSource ) io.close( fileDest ) end local DB = system.pathForFile(dbName, system.DocumentsDirectory) local dbNew = sqlite3.open( DB ) return dbNew end db = setUpDatabase("data.db")
You should test the value of fileSource after the io.open call. If it fails, it will return nil then the next line will fail. It would be helpful if you had copy/pasted the entire error message and complete back trace. Can you verify the line number is the second line above?
Also you can print out the value of pathSource to make sure it’s what you think it is.
As for differences? Windows and OS X are radically different operating systems. For instance, on OS X, when reading in a text file, lines are traditionally separated by newline characters (CTRL-L or \n or Line Feed). Windows uses a line ending that is two characters long: carriage return + line feed (CTRL-M CTRL-L or \r\n). Windows is likely to corrupt files more than OS X will.
You should test the value of fileSource after the io.open call. If it fails, it will return nil then the next line will fail. It would be helpful if you had copy/pasted the entire error message and complete back trace. Can you verify the line number is the second line above?
Also you can print out the value of pathSource to make sure it’s what you think it is.
As for differences? Windows and OS X are radically different operating systems. For instance, on OS X, when reading in a text file, lines are traditionally separated by newline characters (CTRL-L or \n or Line Feed). Windows uses a line ending that is two characters long: carriage return + line feed (CTRL-M CTRL-L or \r\n). Windows is likely to corrupt files more than OS X will.