Crash on http Job

marcel

Active Member
Licensed User
Longtime User
Hi,

Finally I have found some errors where my application is crashing on. I am using the HTTPJob. I am using in JobDone something like:

If job.Success = True Then
If job.JobName="jds" Then
Log(job.GetString)
end if
end if

This results sometimes in:

httpjob_getstring2 (java line: 175)
java.io.FileNotFoundException: /data/data/com.yazula.android/cache/85: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:416)
at java.io.FileInputStream.<init>(FileInputStream.java:78)
at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:197)
at com.yazula.android.httpjob._getstring2(httpjob.java:175)
at com.yazula.android.httpjob._getstring(httpjob.java:164)
at com.yazula.android.helpers._jobdone(helpers.java:420)
at com.yazula.android.update._jobdone(update.java:138)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
at anywheresoftware.b4a.keywords.Common$4.run(Common.java:884)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(Native Method)
Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
at libcore.io.IoBridge.open(IoBridge.java:400)
... 19 more


which is this function:

'Returns the response as a string.
Public Sub GetString2(Encoding As String) As String
Dim tr As TextReader
tr.Initialize2(File.OpenInput(HttpUtils2Service.TempFolder, taskId), Encoding)
Dim res As String
res = tr.ReadAll
tr.Close
Return res
End Sub

I think this function should check if the file still exist or not?!? Correct?
 
Last edited:

mc73

Well-Known Member
Licensed User
Longtime User
Why not simply checking if the file exists?
B4X:
if file.Exists ("yourDir","yourFile") =true then
Why should you leave another function do this check, when I don't see the reason why it should do this check?
 
Upvote 0

marcel

Active Member
Licensed User
Longtime User

Well, because it is a kind of "library" and in the next update this function will be overwritten. So this should be basicly implemented in the 'HttpUtils2 version 2.00 from Erel. Right?
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
I see your point. I never used httpUtils2, now I check it. Seems to me, that it had no reason to do the check, since file should exist.
How do you initialize your 'job'? I mean, what are you sending and requesting?
 
Upvote 0

marcel

Active Member
Licensed User
Longtime User
I see your point. I never used httpUtils2, now I check it. Seems to me, that it had no reason to do the check, since file should exist.
How do you initialize your 'job'? I mean, what are you sending and requesting?

I do just a simple json transfer. I post to an url and get a simple json file back.

This works for 90% of the time just ok. But sometimes not and then I get this crash.
 
Upvote 0

marcel

Active Member
Licensed User
Longtime User
If Success is true then the file should exist. Can you post the JobDone sub?

Apperntly it doesn't sometimes?!?

It crashes on the line:

Dim res As String = job.GetString

B4X:
Sub JobDone (job As HttpJob)
    Dim js As JSONParser
   Dim Map1 As Map
   Dim Jds As List
   Log("JobName = " & job.JobName & ", Success = " & job.Success)
   If job.Success = True Then
     Dim res As String = job.GetString
      If job.JobName="jds" Then
      js.Initialize(res)
      Map1 = js.NextObject
      Jds = Map1.Get("ListItems")
      Update.mtimestamp = Map1.Get("timestamp")
      For Each item In Jds
        ' dump to database
      Next
     Else If job.JobName="segs" Then
       Dim Segs As List
      js.Initialize(res)
      Map1 = js.NextObject
      Segs = Map1.Get("Segments")
      Update.segtimestamp = Map1.Get("timestamp")   
      For Each item In Segs
        'dump to database
      Next
     End If
   Else
      Log("Error: " & job.ErrorMessage)
      'ToastMessageShow("Error: " & job.ErrorMessage, True)
   End If
   job.Release
End Sub
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Just wondering, when you receive the error, do you really get data from your server, or you have a blank response?
 
Upvote 0

marcel

Active Member
Licensed User
Longtime User
Are you able to reproduce it? If yes then please send me the project by mail and I'll check it.

No, unfortunatly not. This is the hard thing. It happens just once on my device. But I have 8 beta testers in the field that had a few crashes which tracked back to this point.

I do fire-up multiple jobs. Could that not be a problem that the same taskid pop-up in some situations
 
Upvote 0

marcel

Active Member
Licensed User
Longtime User
Ok. Well I spend alsmost a day on it to find it but it very hard becuase it is also not reproducable. The trick with the file.exist is at least working...
 
Upvote 0

wolvo66

Member
Licensed User
Longtime User
I just hit exactly the same problem as marcel... This happens every time for me when I activate airplane mode and post data.
I can fix it with the fie.exist change to the httpJob file as described above, but then that introduces another problem that my app stops running when screen is off :/ (I have service with startForeground, notification icon shown etc and it ran fine even with screen off.... until I add the file.exist fix, then it stalls the app execution until screen is active)

Any ideas? I need the app to run long term and withstand loss of network connection
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…