Android Question Unknown errors

FrankBerra

Active Member
Licensed User
Longtime User
Hi all

Sometimes i receive on google Play Console random crash reports from some devices:
B4X:
java.lang.RuntimeException:
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3045)
at android.app.ActivityThread.access$2200(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1454)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5525)
at java.lang.reflect.Method.invoke(Native Method:0)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
Caused by: java.lang.RuntimeException:
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:216)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:163)
at test.app.check.handleStart(check.java:102)
at test.app.check.onStartCommand(check.java:70)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3028)

What does that mean?

And also i receive this "File not found exception", but how to know which file is referring to?
B4X:
java.io.FileNotFoundException:
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:370)
at test.app.starter._application_error(starter.java:176)
at java.lang.reflect.Method.invoke(Native Method:0)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:179)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:897)
at anywheresoftware.b4a.keywords.Common.CallSubNew3(Common.java:847)
at anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.handleUncaughtException(ServiceHelper.java:118)
at java.lang.reflect.Method.invoke(Native Method:0)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:205)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:163)
at test.app.starter.onCreate(starter.java:55)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2895)
at android.app.ActivityThread.access$1900(ActivityThread.java:157)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1439)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5525)
at java.lang.reflect.Method.invoke(Native Method:0)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
Caused by: android.system.ErrnoException:
at libcore.io.Posix.open(Native Method:0)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
at libcore.io.IoBridge.open(IoBridge.java:438)
 

FrankBerra

Active Member
Licensed User
Longtime User
The Application_Errors sub is this:

B4X:
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean 
       
    Dim P As Phone
   
    Dim jo As JavaObject
    Dim l As Long = 500
    jo.InitializeStatic("java.lang.Thread").RunMethod("sleep", Array(l)) 
    logcat.LogCatStop
    logs.Append(StackTrace)
   
    Dim SalvaCrash As TextWriter
    SalvaCrash.Initialize(File.OpenOutput(File.DirDefaultExternal, "CrashReport.txt", True))
    SalvaCrash.WriteLine(DateTime.Date(DateTime.Now) & " - " & DateTime.Time(DateTime.Now))
    SalvaCrash.WriteLine("Manufacturer: " & P.Manufacturer)
    SalvaCrash.WriteLine("Model: " & P.Model)
    SalvaCrash.WriteLine("Product: " & P.Product)
    SalvaCrash.WriteLine("Versione Android: " & P.SdkVersion)
    SalvaCrash.WriteLine("Versione App: " & GetVersionCode)
    SalvaCrash.WriteLine("Versione Sub App: " & getVersion)
    SalvaCrash.WriteLine(logs.ToString)
    SalvaCrash.WriteLine("=============================================")
    SalvaCrash.close
   
    Return True
End Sub

The only file used is "CrashReport.txt" that it is opened with File.OpenOutput.
The help popup about File.OpenOutput says: "Opens (or creates) the specified file which is located in the Dir folder for writing".
That means that if the file is not there it creates a new one and this behaviour is working correctly on almost all devices but on some other devices it creates problems and i receive a crash report on google developer console.
Is there a way to avoid this problem or should i use Try-Catch also in the sub Application_Error? :-D
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Try it:
B4X:
Sub Process_Globals
    Private logs As StringBuilder
    Private logcat As LogCat
    Private const emailAddress As String = "my.email@gmail.com"

Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    'wait for 500ms to allow the logs to be updated.
    Dim jo As JavaObject
    Dim l As Long = 500
    jo.InitializeStatic("java.lang.Thread").RunMethod("sleep", Array(l))
    logcat.LogCatStop
    logs.Append(StackTrace).Append(CRLF).Append(Error).Append(CRLF)
    logs.Append(DateTime.Date(DateTime.Now) & " - " & DateTime.Time(DateTime.Now)).Append(CRLF)
    logs.Append("Manufacturer: " & P.Manufacturer).Append(CRLF)
    logs.Append(Model: " & P.Model).Append(CRLF)
    logs.Append("Product: " & P.Product).Append(CRLF)
    logs.Append("Versione Android: " & P.SdkVersion).Append(CRLF)
    logs.Append("Versione App: " & GetVersionCode).Append(CRLF)
    logs.Append("Versione Sub App: " & getVersion).Append(CRLF)

    Dim email As Email
    email.To.Add(emailAddress)
    email.Subject = "My App - crashed"
    email.Body = logs
    StartActivity(email.GetIntent)

    Return True
End Sub
 
Upvote 0

FrankBerra

Active Member
Licensed User
Longtime User
Thanks but in this case the user must send the report using it's own email address. Maybe someone doesn't want to send logs exposing his email address or don't have time to click on send...
That's why i decided to save a file and let the app itself to send the file to server automatically when the service/app restarts after crash
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
You are trying to save to "defaultexternal", May bem interessante newer devices it needs user autorisation... or it simply is not available...
I dont recall the exact fonder, but there is a writable "appfolder" That you could try
 
Upvote 0

FrankBerra

Active Member
Licensed User
Longtime User
Actually the app is in development state and all files (images, databases, etc) are saved in File.DirDefaultExternal
That user/device from which the error is rised has already saved other files in File.DirDefaultExternal so i can't understand why sometimes it fall in trouble to save a simple textfile.
Due to the fact that the app is just crashed and the app wants to save logs to File.DirDefaultExternal, is it possible that the OS immediately after a crash stops writings to File.DirDefaultExternal (or somewhere else)?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Actually the app is in development state and all files (images, databases, etc) are saved in File.DirDefaultExternal
It probably raised an error when it tried to write to File.DirDefaultExternal and then raise another one in Application_Error.

You should check that File.ExternalWriteable return true.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…