Android Question Fatal Exception: java.io.FileNotFoundException

fasilosman

Active Member
Licensed User
Longtime User
I got an error from firebase console. I couldn't find it.
I am not using http job in main activity. Could anyone help to find out the error.

B4X:
Fatal Exception: java.io.FileNotFoundException: /data/user/0/serandib.jobs/cache/67: open failed: ENOENT (No such file or directory)
       at libcore.io.IoBridge.open(IoBridge.java:452)
       at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
       at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:448)
       at anywheresoftware.b4a.samples.httputils2.httputils2service._hc_responsesuccess(httputils2service.java:178)
       at java.lang.reflect.Method.invoke(Method.java)
       at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
       at anywheresoftware.b4a.BA$2.run(BA.java:365)
       at android.os.Handler.handleCallback(Handler.java:739)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:148)
       at android.app.ActivityThread.main(ActivityThread.java:7331)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

B4X:
Caused by android.system.ErrnoException: open failed: ENOENT (No such file or directory)
       at libcore.io.Posix.open(Posix.java)
       at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
       at libcore.io.IoBridge.open(IoBridge.java:438)
       at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
       at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:448)
       at anywheresoftware.b4a.samples.httputils2.httputils2service._hc_responsesuccess(httputils2service.java:178)
       at java.lang.reflect.Method.invoke(Method.java)
       at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
       at anywheresoftware.b4a.BA$2.run(BA.java:365)
       at android.os.Handler.handleCallback(Handler.java:739)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:148)
       at android.app.ActivityThread.main(ActivityThread.java:7331)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
 

DonManfred

Expert
Licensed User
Longtime User
I am not using http job in main activity
but somewhere you do. And you miss posting the relevant code and result subs (JobDone).
How should we help? I don´t like fishing but if i should guess i would say you are accessing job.getstring or similar when job.success is false
 
Upvote 0

fasilosman

Active Member
Licensed User
Longtime User
but somewhere you do. And you miss posting the relevant code and result subs (JobDone).
How should we help? I don´t like fishing but if i should guess i would say you are accessing job.getstring or similar when job.success is false

01. I am using http jobs in other activities but not in main activity and no jobdone sub. (as in error log - "android.app.ActivityThread.main(ActivityThread.java:7331)")

02. I searched in whole project I always use job done as follows.
B4X:
Sub JobDone(Job As HttpJob)
    If Job.Success Then

        Log (Job.GetString)
        Dim res As String
        Dim Rec As List
        res = Job.GetString
        
        Dim parser As JSONParser
        parser.Initialize(res )
........

if you want I may post all code from main activity.
 
Upvote 0

fasilosman

Active Member
Licensed User
Longtime User
Upload a small project which shows the issue. Hard to help with this less infos.
Only few devices generate the errors. My testing devices or emulators does not generate the error.
I am sorry, I could not find in which activity or service the error is generated. almost all have http job function. Only option is to upload entire project.

From the error report do you think it is not from the main activity.
this is the main.

B4X:
#Region  Project Attributes
    #ApplicationLabel: xxxx
    #VersionCode: 10
    #VersionName: 3.0
    'SupportedOrientation possible values: unspecified, landscape or portrait.
    #SupportedOrientations: Portrait
    #CanInstallToExternalStorage: False
#End Region
    #AdditionalRes: ..\Resource
    #additionaljar: com.android.support:support-v4
    #AdditionalJar: com.crashlytics.sdk.android:crashlytics
    #AdditionalJar: com.google.firebase:firebase-core

#Region  Activity Attributes
    #FullScreen: True
    #IncludeTitle: false
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim Lan As String
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim tt As Timer
    Dim SQLF As SQL

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Dim Qry As String

'    If GetDeviceLayoutValues.Scale > 1 Then
'        SCL = 1 '  GetDeviceLayoutValues.Scale '+ .2
'    Else
'        SCL = 1
'    End If
    
    'Log("scale -- "  & SCL)
    Log(GetDeviceLayoutValues)
    Log("ddddd " & 1%X & " - " & 1%Y)
    tt.Initialize("TT",2000)
    tt.Enabled = True
    Activity.LoadLayout("Main")
    If Not(File.Exists(File.DirInternal,"setting.inf")) Then
        SQLF.Initialize(File.DirInternal,"setting.inf",True)
    Else
        If SQLF.IsInitialized =False Then
            SQLF.Initialize(File.DirInternal,"setting.inf",True)
        End If
    End If

'File.Copy(File.DirInternal,"setting.inf",File.DirDefaultExternal,"a.db")
    
    Qry="CREATE TABLE IF NOT EXISTS Setting (Lan TEXT,ID INT)"
    SQLF.BeginTransaction
    SQLF.ExecNonQuery(Qry)
    SQLF.TransactionSuccessful
    SQLF.EndTransaction

    Qry="CREATE TABLE IF NOT EXISTS Saved (ID INT, CATID INT, CAT TEXT, TITLE TEXT, HTML TEXT)"
    SQLF.BeginTransaction
    SQLF.ExecNonQuery(Qry)
    SQLF.TransactionSuccessful
    SQLF.EndTransaction

'StartService(Noti)
End Sub

Sub Activity_Resume
    tt.Enabled=True
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    tt.Enabled=False

End Sub

Sub tt_tick
    tt.Enabled=False
    'StartActivity("main")
    
    Dim C As Cursor
    c = SQLF.ExecQuery("Select * from setting")
    
    If C.RowCount = 0 Then
        StartActivity("startup")
        Activity.Finish
    Else
            
        C.Position=0
            Lan = C.GetString("Lan")
        If (Lan = "EN") Or (Lan = "TM") Or (Lan="SN") Then
            StartActivity("Home")
            Activity.Finish
        Else
            StartActivity("startup")
            Activity.Finish

        End If

    End If
    


End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
as in error log - "android.app.ActivityThread.main(ActivityThread.java:7331)")
i don´t think this is a reference to your MAIN module from your project.
If it were such a ref it would be something like b4a.example.Main
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Two mistakes here:
B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim tt As Timer
    Dim SQLF As SQL

End Sub
Timers and SQL objects should not be declared as non-process globals.

About the error message, which version of OkHttpUtils2 are you using?
 
Upvote 0

fasilosman

Active Member
Licensed User
Longtime User
Two mistakes here:

Timers and SQL objects should not be declared as non-process globals.

About the error message, which version of OkHttpUtils2 are you using?

01. Thank you. I will correct those mistakes.
02. OkHttpUtils2 - version - 2.70
 
Upvote 0

fasilosman

Active Member
Licensed User
Longtime User
@Erel - Happy New Year 2019 - Wishing you all the best.

Sorry to say that the error raises again. I checked all modules for job.realese and it is fine. Following is a sample of job done sub.

B4X:
Sub JobDone(Job As HttpJob)
    If Job.Success Then

        Dim res As String
        Dim Rec As List
        res = Job.GetString
      

        If res = "" Then
            Return
        End If
      
        Dim parser As JSONParser
        parser.Initialize(res )


        Select Job.JobName
          
            Case "lst"

                Rec.Initialize
                Rec = parser.NextArray
                Dim m As Map

                If Rec.Size = 0 Then
                  
                Else
                  
                    For Xn  = 0 To Rec.Size-1
                      
                      
                        Dim ItemMap As Map
                      
                        ItemMap = Rec.Get(Xn)
                      
                        If Main.Lan = "TM" Then
                            If ItemMap.Get("T") <> "" Then
                                Clist.Add(CreateItem(ItemMap.Get("ID"),ItemMap.Get("T"),ItemMap.Get("E"),ItemMap.Get("S")),80dip,ItemMap.Get("ID"))
                            End If
                        else if Main.Lan = "EN" Then
                            If ItemMap.Get("E") <> "" Then
                                Clist.Add(CreateItem(ItemMap.Get("ID"),ItemMap.Get("T"),ItemMap.Get("E"),ItemMap.Get("S")),80dip,ItemMap.Get("ID"))
                            End If
                        else if Main.Lan = "SN" Then
                            If ItemMap.Get("S") <> "" Then
                                Clist.Add(CreateItem(ItemMap.Get("ID"),ItemMap.Get("T"),ItemMap.Get("E"),ItemMap.Get("S")),80dip,ItemMap.Get("ID"))
                            End If
                        End If

                      
                      
                      
                    Next
                  

                  
                End If
          

        End Select
      
    Else
        Log(Job.ErrorMessage)
        ToastMessageShow("Unable to process. Please check the internet connection.", True)

    End If
Job.Release
End Sub
 
Last edited:
Upvote 0

fasilosman

Active Member
Licensed User
Longtime User
How many reports of this error do you see? Such errors can happen from time to time. For example if the storage becomes full.
OH. may be.

12 events from 6 users - active users around 120.

Do we have any coding to display any message or avoid error/crash in such situations like try, catch. If so where to use them (I mean the position in the coding)
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
12 events from 6 users - active users around 120.
Sounds like a real issue.

The error happens inside httputils2service._hc_responsesuccess. It fails to open an OutputStream. You can use the source code instead of the library and catch this error.

Based on the file name (/data/user/0/serandib.jobs/cache/67) it happened after 67 downloads. This is a strange error. I don't remember seeing such reports so I guess that you are doing something wrong.
 
Upvote 0

fasilosman

Active Member
Licensed User
Longtime User
so I guess that you are doing something wrong.

I am using a sub to call multiple httpjobs

B4X:
Sub RunHt(Jobname As String,Jobstring As String)

    Dim Job As HttpJob
    Job.Initialize(Jobname,Me)
    Job.Download (Jobstring)

End Sub

Then I call like this multiple time/links

B4X:
    RunHt("Omenu","http://xxxxxxx.php?action=viewomenu")
    RunHt("Oitems","http://xxxxxxx.php?action=viewoitem")

Is this will be an issue.
 
Upvote 0
Top