Fail on FileStream.Open() [solved]
Monkey Targets Forums/Android/Fail on FileStream.Open() [solved]
| ||
Hi, I am having an issue trying to load a text file (.txt) using FileStream.Open(). It work in Glfw3/2 and I am opening a text file with the extension '.txt' and that should be good with 'CONFIG.MONKEY'. Here is an example of how I open the file, Local test:String= "monkey://data/system_resources/client_skin/client_skin.txt" Local stream:=FileStream.Open(test,"r") Since it runs in Glfw the path and file name are good and I can't see a reason the stream returns as null. Using Monkey 82b. Stuck on this one. :) |
| ||
Hi, Well stream looks like it is not Null. I added an 'IF' statement to end the app if the stream is Null and the app crashes instead of ending. So stream is not Null. What I am doing is loading a text file and parsing that to load images, which seem not to be loading as all images (that are parsed) are Null. (although they load and work in Glfw). The image variables are global's and not in a class, is that a problem in Android? There is a fail in compiler output. What does this output from Monkey mean ( [exec] rm failed for -f, Read-only file system )? install: [echo] Installing C:\Programming\phoenix2d\gui_test.buildv82b\android_new\bin\MonkeyGame-debug.apk onto default emulator or device... [exec] pkg: /data/local/tmp/MonkeyGame-debug.apk [exec] Success [exec] 1338 KB/s (1306595 bytes in 0.953s) [exec] rm failed for -f, Read-only file system A little hard to debug in working with android so I'm kind of searching for the issue. Edit- I thought maybe white spaces were a no-no but seem OK. Perhaps the way I'm reading a line from a string does not work in Android. Using FromChar(KEY_ENTER) to get the end of a line (see below). Stumped. Local newss:String Local test:String= "monkey://data/mytextfile.txt" Local stream:=FileStream.Open(test,"r") 'If stream=Null Then EndApp() If stream<>Null Local cnt:Int=1 While Not stream.Eof() newss=stream.ReadString() newss.Trim() Local strend:Int=newss.Length()-1 Local start:Int=0 Local strcnt:Int For Local ts:Int=1 To strend+1 If mys=String.FromChar(KEY_ENTER) Or ts=strend+1 'Use parsed data to load an image file Endif Next Wend Endif |
| ||
Compile in debug mode, and then use DDMS to monitor the output and do a stack trace on where exactly this is getting choked up. I'm not exactly sure what the problem could be, but if the file is loading correctly, then I suspect possibly the output is not sanitized properly for what your parser is expecting. You can try using String.Trim() on the filestream's output, but the right way to handle it would probably be to inspect the stack trace in DDMS. |
| ||
At least from what it sounds like, you're unable to properly upload/auto-install your APK file. Basically, it's trying to remove the old one, but it doesn't have write-permissions. Assuming this is correct, your code in Monkey isn't actually being ran. Either that, or you're for some reason deleting a file in your own program. Considering you don't get any debug information (Line numbers), and it is actually running (Which I kind of doubt), then it's an issue in the native code. My guess is it's not installing on the device properly. See if you can uninstall it yourself, then try building it again. Also, for future reference, you can write: And your call to the parameterless version of 'ReadString' yields the same result as 'LoadString' (Reads the entire file). |
| ||
use DDMS to monitor the output and do a stack trace on where exactly this is getting choked up I'll give it a try. I'm getting Android studio now as I just have the SDK. As I understand it DDMS should work fine with the SDK emulator which is what I am using. I suspect possibly the output is not sanitized properly for what your parser is expecting This is a likely possibility and I might take a stab at using another method or trying to verify that I am indeed finding 'KEY_ENTER' using FromChar(KEY_ENTER). Also to verify that I am getting string data. At least from what it sounds like, you're unable to properly upload/auto-install your APK file I believe I am able to get the app on the emulator. I can run my own banana's samples on it so it looks as if that is not an issue.I have a VirtualBox going with Android as well and the above build fails on it as well so the emulator is probably OK despite the '[exec] rm failed for -f, Read-only file system' message which still concerns me and may be an issue. Although I have created new devices in the emulator and each one will return that error. And your call to the parameterless version of 'ReadString' yields the same result as 'LoadString' (Reads the entire file). I will try LoadString() and see if that yields any good results. Thanks for the responses. The rest of my code works great it's just this file read issue. |
| ||
Is it possible that Android files only have LF and not CR/LF ? I wouldn't think so since it should be using your txt file as exact.... Just a thought. http://en.wikipedia.org/wiki/Newline |
| ||
OK, So I guess stream.ReadSring() works differently in Glfw then it does in Android. Using LoadString() instead will work in both Android and Glfw. So this works in Glfw but 'NOT' Android. Local newss:String Local test:String= "monkey://data/mytextfile.txt" Local stream:=FileStream.Open(test,"r") If stream<>Null Local cnt:Int=1 While Not stream.Eof() newss=stream.ReadString() newss.Trim() Local strend:Int=newss.Length()-1 Local start:Int=0 Local strcnt:Int For Local ts:Int=1 To strend+1 Local mys:String=newss[ts..(ts+1)] If mys=String.FromChar(KEY_ENTER) Or ts=strend+1 'Use parsed data to load an image file Endif Next Wend Endif . Am I not getting how stream.ReadString() works or is there an issue with the Android target? . Using LoadString works for both Glfw and Android as show here. Local newss:String newss=LoadString(("monkey://data/mytext.txt")) newss.Trim() Local strend:Int=newss.Length()-1 Local start:Int=0 Local strcnt:Int For Local ts:Int=1 To strend+1 Local mys:String=newss[ts..(ts+1)] If mys=String.FromChar(KEY_ENTER) Or ts=strend+1 'Use parsed data to load an image file Endif Next Thanks all for the responses. :D It really helps working through the problem. |