Note that there are some explanatory texts on larger screens.

plurals
  1. POLogic breakdown - unexpected behavior testing value
    primarykey
    data
    text
    <p>I've got a function which looks in android assets and loads if asset exists. If Not then looks on file system. If it finds it, it loads it - if file not zero bytes. If not found on file system it makes 2 attempts to get it from a server. All of this works except if the the file is already there and the size is 0 - and its failing on some "primitive" java logic test. I can't see what is wrong here and exploring the possibility of it being a bug outside of my own code.</p> <p>The problem is occurring at </p> <pre><code>if (lenoffile&gt;1){ // always fails </code></pre> <p>where any check of this int against 0 causes the function to return and not execute the expected flow.</p> <pre><code>private String readQuestions(String xml_file){ Log.i(TAG2,"readQuestions"); List&lt;String&gt; mapList = null; String xmlString = null; int lenoffile =0; AssetManager am = this.getAssets(); try { mapList = Arrays.asList(am.list("")); if (mapList.contains(xml_file)){ InputStream is = am.open(xml_file); int length = is.available(); byte[] data = new byte[length]; is.read(data); xmlString = new String(data); return xmlString; } } catch (IOException e1) { Log.i(TAG,"Failed in ReadQuestions() from assets"); // e1.printStackTrace(); //return null; } Log.i(TAG2,"File not an asset. Must be on FS"); if (me.FileExists(Environment.getExternalStorageDirectory().getAbsolutePath() + APPDIR +"/"+xml_file)) xmlString = m.fileLoader(xml_file); if (xmlString != null){ lenoffile = xmlString.length(); Log.i(TAG2,"Length of file found=" + lenoffile); if (lenoffile&gt;1){ // below never gets executed even with lenoffile==0 Log.i(TAG2,"Returning here with a file of length "+ lenoffile); return xmlString; // assume the full file exists and validate } } // if else then there is a null situation else{ // look on FS and load accordingly DownloadFileAsync Z = new DownloadFileAsync(); </code></pre> <p>trace:</p> <pre><code>06-09 12:26:58.197: I/SRCFILE(11792): readQuestions 06-09 12:27:08.822: I/SRCFILE(11792): File not an asset. Must be on FS 06-09 12:27:15.197: I/SRCFILE(11792): Length of file found=0 </code></pre> <p>Thanks in advance.</p> <p>Kevin</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload