Hello, I have a text file hosted on Olympe.in and when my device wants to retrieve on the internet it gives me this error, yet it seems to me that I put all the correct permissions
Please help me
Hello, I have a text file hosted on Olympe.in and when my device wants to retrieve on the internet it gives me this error, yet it seems to me that I put all the correct permissions
Please help me
Hi Kevin,
Please refer to the following guide under “Android Build Settings” and make sure that you configured all of the permissions properly:
http://docs.coronalabs.com/guide/distribution/buildSettings/index.html#androidsettings
Regards,
Brent Sorrentino
Thank you Brent, my permissions are good but the file txt don’t display!
i think it’s because have this error!!
[sharedmedia=core:attachments:418]
Can you copy and paste your code where you are trying to download the file and open it? Please include it in and
tags (take out the space after the bracket).
Also paste in your build.settings file.
Yes :
[code]
– view2.lua
–
ligne = {}
local storyboard = require( “storyboard” )
local scene = storyboard.newScene()
local function networkListener ( event )
local path = system.pathForFile( event.response.filename, event.response.baseDirectory )
local file = io.open( path, “r” )
nbr_ligne=1
for line in file:lines() do
ligne[nbr_ligne] = tostring(line)
nbr_ligne=nbr_ligne+1
end
io.close( file )
file = nil
nbr_pronos = (nbr_ligne-1)/4
for i = 1,nbr_pronos do
ligne[i] = display.newText( ligne[i], 10, 10*i, native.systemFont, 24)
ligne[i]:setTextColor(0,0,0)
end
end
network.download(
“http://devkevin.olympe.in/pronostics.txt”,
“GET”, networkListener,“pronostics.txt”,system.TemporaryDirectory
)
[/code]
the first big bloc is a at the beginning of the view 2 and the network download after in the code when i want he appaer.
what do you want copy in build setting?
yes, please post your build.settings file. I dunno what happend with your code tags though. Looks like the closing one still has a space in it. I don’t know what the code=auto;0 is either. Though I think I see the problem.
Your networkListener is going to get called multiple times. There is an event.phase member of the event table that tells you what phase you are in. They include “began”, “ended” and potentially “progress” if you have the right settings. So when the began phase happens, you don’t have a file to open yet so your app crashes. Please add:
if event.phase == “ended” then
and
end
around your code inside of your networkListener function and see if that helps. You should also check inside that ended phase to make sure that event.isError is false. If it’s true, your connection timed out or the server was down for some reason. You should also check event.response (or maybe event.status) and look for some 200 code at the beginning (any 2XX value actually) to indicate it was successful. The event.isError can be false meaning it successfully talked to the file server, but still not find your file. If you get any 4XX or 5XX codes then it failed to retrieve the file and you should handle those conditions accordingly.
This is my build.setting file :
-- Supported values for orientation: -- portrait, portraitUpsideDown, landscapeLeft, landscapeRight settings = { orientation = { default = "portrait", supported = { "portrait", } }, android = { versionCode = "1", usesPermissions = { "android.permission.INTERNET", "android.permission.WRITE\_EXTERNAL\_STORAGE", }, }, }
and my view 2 where is the network.listener.
----------------------------------------------------------------------------------------- -- -- view2.lua -- ----------------------------------------------------------------------------------------- ligne = {} local storyboard = require( "storyboard" ) local scene = storyboard.newScene() local function networkListener ( event ) local path = system.pathForFile( event.response.filename, event.response.baseDirectory ) local file = io.open( path, "r" ) nbr\_ligne=1 for line in file:lines() do ligne[nbr\_ligne] = tostring(line) nbr\_ligne=nbr\_ligne+1 end io.close( file ) file = nil nbr\_pronos = (nbr\_ligne-1)/4 for i = 1,nbr\_pronos do ligne[i] = display.newText( ligne[i], 10, 10\*i, native.systemFont, 24) ligne[i]:setTextColor(0,0,0) end end ----------------------------------------------------------------------------------------- -- BEGINNING OF YOUR IMPLEMENTATION -- -- NOTE: Code outside of listener functions (below) will only be executed once, -- unless storyboard.removeScene() is called. -- ----------------------------------------------------------------------------------------- -- Called when the scene's view does not exist: function scene:createScene( event ) local group = self.view local physics = require "physics" physics.start() -- create a white background to fill screen --local bg = display.newImage( "pronostics4.png" ) --local bgp = display.newImage( "Pronostics2.png" ) local grass = display.newImage( "grass.png" ) grass.y = 480 physics.addBody( grass, "static", { friction =0.1 } ) --ballon local crate = display.newImage( "ballonbasket.png" ) crate.x, crate.y = 130, 50 crate.rotation = 50 crate.width = 60 crate.height = 60 physics.addBody( crate, { bounce=1 } ) physics.addBody( grass, "static", { friction =0.1 } ) --ballon local crate = display.newImage( "ballonfoot.png" ) crate.x, crate.y = 190, 50 crate.rotation = 70 crate.width = 60 crate.height = 60 physics.addBody( crate, { bounce=1 } ) physics.addBody( grass, "static", { friction =0.1 } ) --ballon local crate = display.newImage( "balletennis.png" ) crate.x, crate.y = 170, 50 crate.rotation = 50 crate.width = 30 crate.height = 30 physics.addBody( crate, { bounce=1 } ) network.download( "http://devkevin.olympe.in/pronostics.txt", "GET", networkListener,"pronostics.txt",system.TemporaryDirectory ) if event.phase == "ended" then and end -- create some text --local title = display.newText( "Pronostics", 0, 0, native.systemFont, 32 ) -- title:setTextColor( 255 ) -- white -- title:setReferencePoint( display.CenterReferencePoint ) -- title.x = 90 -- title.y = 50 -- local summary = display.newText( "Loaded by the first tab 'onPress' listener\n— specified in the 'tabButtons' table.", 0, 0, 300, 300, native.systemFont, 14 ) -- summary:setTextColor( 0 ) -- black -- summary:setReferencePoint( display.CenterReferencePoint ) -- summary.x = display.contentWidth \* 0.5 + 10 -- summary.y = title.y + 215 -- all objects must be added to group (e.g. self.view) -- group:insert( bg ) -- group:insert( bgp ) group:insert( grass ) -- group:insert( summary ) end -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) local group = self.view -- do nothing end -- Called when scene is about to move offscreen: function scene:exitScene( event ) local group = self.view -- INSERT code here (e.g. stop timers, remove listenets, unload sounds, etc.) end -- If scene's view is removed, scene:destroyScene() will be called just prior to: function scene:destroyScene( event ) local group = self.view -- INSERT code here (e.g. remove listeners, remove widgets, save state variables, etc.) end ----------------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION ----------------------------------------------------------------------------------------- -- "createScene" event is dispatched if scene's view does not exist scene:addEventListener( "createScene", scene ) -- "enterScene" event is dispatched whenever scene transition has finished scene:addEventListener( "enterScene", scene ) -- "exitScene" event is dispatched whenever before next scene's transition begins scene:addEventListener( "exitScene", scene ) -- "destroyScene" event is dispatched before view is unloaded, which can be -- automatically unloaded in low memory situations, or explicitly via a call to -- storyboard.purgeScene() or storyboard.removeScene(). scene:addEventListener( "destroyScene", scene ) ----------------------------------------------------------------------------------------- return scene
I meant this:
local function networkListener ( event ) if event.isError then print("server timed out"); -- handle this error condition here else if event.phase == "ended" then local path = system.pathForFile( event.response.filename, event.response.baseDirectory ) local file = io.open( path, "r" ) nbr\_ligne=1 for line in file:lines() do ligne[nbr\_ligne] = tostring(line) nbr\_ligne=nbr\_ligne+1 end io.close( file ) file = nil nbr\_pronos = (nbr\_ligne-1)/4 for i = 1,nbr\_pronos do ligne[i] = display.newText( ligne[i], 10, 10\*i, native.systemFont, 24) ligne[i]:setTextColor(0,0,0) end end end end
copy the code again, I missed a “then” after the if event.phase == “ended”…
Up please its very important for me…
Can you post your current code?
I dont understand curent code …
What do you want on m’y code ?
Thanks
You posted your view2.lua code above but have changed it since then. Can you post the latest version here so I can look at it?
this is my view2.lua now
----------------------------------------------------------------------------------------- -- -- view2.lua -- ----------------------------------------------------------------------------------------- ligne = {} local storyboard = require( "storyboard" ) local scene = storyboard.newScene() local function networkListener ( event ) if event.isError then print("server timed out"); -- handle this error condition here else if event.phase == "ended" then local path = system.pathForFile( event.response.filename, event.response.baseDirectory ) local file = io.open( path, "r" ) nbr\_ligne=1 for line in file:lines() do ligne[nbr\_ligne] = tostring(line) nbr\_ligne=nbr\_ligne+1 end io.close( file ) file = nil nbr\_pronos = (nbr\_ligne-1)/4 for i = 1,nbr\_pronos do ligne[i] = display.newText( ligne[i], 10, 10\*i, native.systemFont, 24) ligne[i]:setTextColor(0,0,0) end end end end ----------------------------------------------------------------------------------------- -- BEGINNING OF YOUR IMPLEMENTATION -- -- NOTE: Code outside of listener functions (below) will only be executed once, -- unless storyboard.removeScene() is called. -- ----------------------------------------------------------------------------------------- -- Called when the scene's view does not exist: function scene:createScene( event ) local group = self.view local physics = require "physics" physics.start() -- create a white background to fill screen --local bg = display.newImage( "pronostics4.png" ) --local bgp = display.newImage( "Pronostics2.png" ) local grass = display.newImage( "grass.png" ) grass.y = 480 physics.addBody( grass, "static", { friction =0.1 } ) --ballon local crate = display.newImage( "ballonbasket.png" ) crate.x, crate.y = 130, 50 crate.rotation = 50 crate.width = 60 crate.height = 60 physics.addBody( crate, { bounce=1 } ) physics.addBody( grass, "static", { friction =0.1 } ) --ballon local crate = display.newImage( "ballonfoot.png" ) crate.x, crate.y = 190, 50 crate.rotation = 70 crate.width = 60 crate.height = 60 physics.addBody( crate, { bounce=1 } ) physics.addBody( grass, "static", { friction =0.1 } ) --ballon local crate = display.newImage( "balletennis.png" ) crate.x, crate.y = 170, 50 crate.rotation = 50 crate.width = 30 crate.height = 30 physics.addBody( crate, { bounce=1 } ) network.download( "http://devkevin.olympe.in/pronostics.txt", "GET", networkListener,"pronostics.txt",system.TemporaryDirectory ) -- create some text --local title = display.newText( "Pronostics", 0, 0, native.systemFont, 32 ) -- title:setTextColor( 255 ) -- white -- title:setReferencePoint( display.CenterReferencePoint ) -- title.x = 90 -- title.y = 50 -- local summary = display.newText( "Loaded by the first tab 'onPress' listener\n— specified in the 'tabButtons' table.", 0, 0, 300, 300, native.systemFont, 14 ) -- summary:setTextColor( 0 ) -- black -- summary:setReferencePoint( display.CenterReferencePoint ) -- summary.x = display.contentWidth \* 0.5 + 10 -- summary.y = title.y + 215 -- all objects must be added to group (e.g. self.view) -- group:insert( bg ) -- group:insert( bgp ) group:insert( grass ) -- group:insert( summary ) end -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) local group = self.view -- do nothing end -- Called when scene is about to move offscreen: function scene:exitScene( event ) local group = self.view -- INSERT code here (e.g. stop timers, remove listenets, unload sounds, etc.) end -- If scene's view is removed, scene:destroyScene() will be called just prior to: function scene:destroyScene( event ) local group = self.view -- INSERT code here (e.g. remove listeners, remove widgets, save state variables, etc.) end ----------------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION ----------------------------------------------------------------------------------------- -- "createScene" event is dispatched if scene's view does not exist scene:addEventListener( "createScene", scene ) -- "enterScene" event is dispatched whenever scene transition has finished scene:addEventListener( "enterScene", scene ) -- "exitScene" event is dispatched whenever before next scene's transition begins scene:addEventListener( "exitScene", scene ) -- "destroyScene" event is dispatched before view is unloaded, which can be -- automatically unloaded in low memory situations, or explicitly via a call to -- storyboard.purgeScene() or storyboard.removeScene(). scene:addEventListener( "destroyScene", scene ) ----------------------------------------------------------------------------------------- return scene
with the same error : http://www.hostingpics.net/viewer.php?id=639600afterdebug2.png
please
change this:
network.download( "http://devkevin.olympe.in/pronostics.txt", "GET", networkListener,"pronostics.txt",system.TemporaryDirectory )
to:
network.download( "http://devkevin.olympe.in/pronostics.txt", "GET", networkListener,"pronostics.txt",system.CachesDirectory )
and see if that makes a difference? I think your Windows isn’t letting you access the systems temporary folder. This could be a local Windows permission problem. If that doesn’t work, then try system.DocumentsDirectory
Your code will likely work on your Android device as is. I think this is a Windows problem.
Yes, your idea about Windows i think the same but i had test caches et documentsdirectory and always the same probleme no open file Stream error…
My file.txt don’t display on the screen !
IT S WORK!!! IN MY DEVICE !!
Two last questions, and i have finish.
My text is normally on my page ‘Pronostics’ ONLY and he display on all pages like you see on photos.
i think is a problem of groupe:insert in my view2.
and second problem, like you can see on photo, my text have 3 lines but the original file 14 lines…
Do you have ideas and thank you very much again…