With the recent tut on i/o, I decided to try something that I’ve wanted to do——Read content from an HTML file; replace whatever is between the and tags with new content (i.e., from another file); and then display the resulting rendered HTML into a webPopUp (can’t use webView b/c it needs to work on Android). Unfortunately, I am getting the infamous “the application has been corrupted” error.
I have read through the many past posts with this same problem and have attempted the many solutions. I have
- checked the capitalization on my file names and in my code,
- moved everything into the base ResourceDirectory,
- renamed my files with a .txt extension.
- created (for good measure) the file to be read into the webPopUp on the fly (unfortunately, this has to be an .html file as that’s what the webPopUp reads)
- copied the files into the actual sandbox folder for this app
- I created a “Documents” folder in the main resource directory.
But all to no avail. I’m not sure how to get this working on Android. It seems as though it should be simple enough. Any ideas? (see my complete code below).
[lua]-- main.lua
– PURPOSE: Test for pattern matching (so that I can eventually replace what occurs between two HTML tags)
_H = display.contentHeight
_W = display.contentWidth
–read in the text from a file
local path1 = system.pathForFile(“container.txt”, system.DocumentsDirectory)
local file = io.open(path1,“r”)
local oldText = file:read("*a")
io.close(file)
–now get the data you’ll use to replace this text
local path2 = system.pathForFile(“content.txt”,system.DocumentsDirectory)
local file2 = io.open(path2,“r”)
local newText = file2:read("*a")
io.close(file2)
file2 = nil
–now try replacing everything between those two indexes
local changedText = string.gsub(oldText, “([%c%w%s%p%d]+)”, “”…newText…"")
–now write the data to a new file
local path3 = system.pathForFile(“newFile.html”,system.DocumentsDirectory)
file = io.open(path3,“w”)
file:write(changedText)
io.close(file)
file = nil
–now let’s load this file into a web popup (can’t use native.webView b/c it only works on iOS devices currently, but look to do it when they come to Android)
local options = {hasBackground = false, baseUrl = system.DocumentsDirectory}
local text = native.showWebPopup(50, 50, _W*.5,_H*.9,“newFile.html”, options)[/lua] [import]uid: 19999 topic_id: 21944 reply_id: 321944[/import]