Android Question Error Code : 1294 (SQLITE_CANTOPEN_ENOENT)

PierPaduan

Active Member
Licensed User
Hi everyone.

I have my app on Google Play.
Crashlytics reported me the following error from one user.

Fatal Exception: java.lang.RuntimeException: Unable to create service it.ritmo.setandgo.starter: java.lang.RuntimeException: android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 1294): Could not open database
#################################################################
Error Code : 1294 (SQLITE_CANTOPEN_ENOENT)
Caused By : Specified directory or database file does not exist.
(unknown error (code 1294): Could not open database)
#################################################################
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3554)
at android.app.ActivityThread.-wrap4(Unknown Source)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1786)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6940)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Caused by java.lang.RuntimeException: android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 1294): Could not open database
#################################################################
Error Code : 1294 (SQLITE_CANTOPEN_ENOENT)
Caused By : Specified directory or database file does not exist.
(unknown error (code 1294): Could not open database)
#################################################################
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:233)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at it.ritmo.setandgo.starter.onCreate(starter.java:56)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3544)
at android.app.ActivityThread.-wrap4(Unknown Source)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1786)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6940)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Caused by android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 1294): Could not open database
#################################################################
Error Code : 1294 (SQLITE_CANTOPEN_ENOENT)
Caused By : Specified directory or database file does not exist.
(unknown error (code 1294): Could not open database)
#################################################################
at android.database.sqlite.SQLiteConnection.nativeOpen(SQLiteConnection.java)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:261)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:204)
at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:633)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:242)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:214)
at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:1184)
at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:1139)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:854)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:829)
at anywheresoftware.b4a.sql.SQL.Initialize(SQL.java:44)
at it.ritmo.setandgo.starter._service_create(starter.java:186)
at java.lang.reflect.Method.invoke(Method.java)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at it.ritmo.setandgo.starter.onCreate(starter.java:56)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3544)
at android.app.ActivityThread.-wrap4(Unknown Source)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1786)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6940)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
It happened five times on a single device:
Brand: samsung
Model: SM-N950U
Android version: 8.0.0

For development I use a Galaxy Samsung S7 Edge with Android 8.0.0 and it works correctly.
I've tried on the S7 to uninstall and install again from Google Play and all works correctly.

I don't know how to fix this problem. Someone can help me?
Thanks a Lot to everyone.

My Starter code is the following:
B4X:
#Region  Service Attributes
    #StartAtBoot: False
#End Region

Sub Process_Globals
    Public sql As SQL
    
    Public rp As RuntimePermissions
    Public SafeDirDefExt As String
    
    Public Provider As FileProvider

    Public CL As Crashlytics        'Per crashlytics
    
End Sub

Sub Service_Create
    
    SafeDirDefExt = rp.GetSafeDirDefaultExternal("")
    
   
    
    'if doesn't exist I create the directory
    If File.Exists(SafeDirDefExt, "/SETandGO/Data") = False Then
        File.MakeDir(SafeDirDefExt, "/SETandGO/Data")
    End If

    If File.Exists(SafeDirDefExt & "/SETandGO/Data", "ReportsButtWeld_v1.db") Then
        'open database
        sql.Initialize(SafeDirDefExt & "/SETandGO/Data", "ReportsButtWeld_v1.db", True)
        
    Else
        'create and open database
        sql.Initialize(SafeDirDefExt & "/SETandGO/Data", "ReportsButtWeld_v1.db", True)
       
        
        DBUtils.CreateTable(sql, "reports",  _
        CreateMap("id": DBUtils.DB_INTEGER, _
        "mo_modello_macchina": DBUtils.DB_TEXT, _
        "pa_tepa": DBUtils.DB_TEXT, _
        "di_diametro": DBUtils.DB_TEXT, _
        "sd_sdr": DBUtils.DB_TEXT, _
        "en_spessore": DBUtils.DB_TEXT, _
        "ma_materiale": DBUtils.DB_TEXT, _
        "st_norma": DBUtils.DB_TEXT, _
        "pi_press_interf": DBUtils.DB_TEXT, _
        "pt_drag": DBUtils.DB_TEXT, _
        "CL_tpmin": DBUtils.DB_TEXT, _
        "CN_tpnom": DBUtils.DB_TEXT, _
        "CH_tpmax": DBUtils.DB_TEXT, _
        "Ab_dim_bord": DBUtils.DB_TEXT, _
        "p1_pbord": DBUtils.DB_TEXT, _
        "p2_prisc": DBUtils.DB_TEXT, _
        "p3_psald": DBUtils.DB_TEXT, _
        "p4_pdual": DBUtils.DB_TEXT, _
        "t1_tbord": DBUtils.DB_TEXT, _
        "t2_trisc": DBUtils.DB_TEXT, _
        "t3_tscambio": DBUtils.DB_TEXT, _
        "t4_trampa": DBUtils.DB_TEXT, _
        "t5_tsald": DBUtils.DB_TEXT, _
        "t6_tdual": DBUtils.DB_TEXT, _
        "t7_traffr": DBUtils.DB_TEXT, _
        "bo_badge": DBUtils.DB_TEXT, _
        "tp_traccia1": DBUtils.DB_TEXT, _
        "ts_traccia2": DBUtils.DB_TEXT, _
        "la_gpslat": DBUtils.DB_TEXT, _
        "lo_gpslon": DBUtils.DB_TEXT, _
        "sn_matricola": DBUtils.DB_TEXT, _        'matricola della saldatrice richiesta e ricevuta ad inizio comunicazione tra app e saldatrice.
        "ns_numsald": DBUtils.DB_TEXT, _        'numero della saldatura ricevuta ad inizio comunicazione +1, deve essere uguale al numero "ns_numsald_rx" che viene ricevuto con il report dalla saldatrice.
        "dd_day_rx": DBUtils.DB_TEXT, _
        "mm_month_rx": DBUtils.DB_TEXT, _
        "yy_year_rx": DBUtils.DB_TEXT, _
        "hh_hour_rx": DBUtils.DB_TEXT, _
        "mi_minute_rx": DBUtils.DB_TEXT, _
        "CP_temptp_rx": DBUtils.DB_TEXT, _
        "CA_tempamb_rx": DBUtils.DB_TEXT, _
        "mr_proxrevmese_rx": DBUtils.DB_TEXT, _
        "ar_proxrevanno_rx": DBUtils.DB_TEXT, _
        "vf_versfirm_rx": DBUtils.DB_TEXT, _
        "sn_matricola_rx": DBUtils.DB_TEXT, _    'matricola della saldatrice ricevuta con il report.
        "di_diametro_rx": DBUtils.DB_TEXT, _
        "ma_materiale_rx": DBUtils.DB_TEXT, _
        "sd_sdr_rx": DBUtils.DB_TEXT, _
        "op_operatore_rx": DBUtils.DB_TEXT, _
        "lu_luogosald_rx": DBUtils.DB_TEXT, _
        "no_note_rx": DBUtils.DB_TEXT, _
        "ns_numsald_rx": DBUtils.DB_TEXT, _        'numero della saldatura ricevuto con il report.
        "pt_drag_real_rx": DBUtils.DB_TEXT, _
        "p1_pbord_teo_rx": DBUtils.DB_TEXT, _
        "p2_prisc_teo_rx": DBUtils.DB_TEXT, _
        "p3_psald_teo_rx": DBUtils.DB_TEXT, _
        "p4_pdual_teo_rx": DBUtils.DB_TEXT, _
        "t1_tbord_teo_rx": DBUtils.DB_TEXT, _
        "t2_trisc_teo_rx": DBUtils.DB_TEXT, _
        "t3_tscambio_teo_rx": DBUtils.DB_TEXT, _
        "t4_trampa_teo_rx": DBUtils.DB_TEXT, _
        "t5_tsald_teo_rx": DBUtils.DB_TEXT, _
        "t6_tdual_teo_rx": DBUtils.DB_TEXT, _
        "t7_traffr_teo_rx": DBUtils.DB_TEXT, _
        "TT_tempo_tot_real_rx": DBUtils.DB_TEXT, _
        "P1_pbord_real_rx": DBUtils.DB_TEXT, _
        "P2_prisc_real_rx": DBUtils.DB_TEXT, _
        "P3_psald_real_rx": DBUtils.DB_TEXT, _
        "P4_pdual_real_rx": DBUtils.DB_TEXT, _
        "T1_tbord_real_rx": DBUtils.DB_TEXT, _
        "T2_trisc_real_rx": DBUtils.DB_TEXT, _
        "T3_tscambio_real_rx": DBUtils.DB_TEXT, _
        "T4_trampa_real_rx": DBUtils.DB_TEXT, _
        "T5_tsald_real_rx": DBUtils.DB_TEXT, _
        "T6_tdual_real_rx": DBUtils.DB_TEXT, _
        "T7_traffr_real_rx": DBUtils.DB_TEXT, _
        "es_esito_rx": DBUtils.DB_TEXT, _
        "note_app": DBUtils.DB_TEXT, _
        "picture_dir": DBUtils.DB_TEXT, _
        "picture1": DBUtils.DB_TEXT, _
        "picture2": DBUtils.DB_TEXT, _
        "punti_fase": DBUtils.DB_TEXT, _            'memorizzo le fasi del ciclo inviate dalla saldatrice durante la saldatura, ognuna seguita da un separatore       
        "punti_tempo": DBUtils.DB_TEXT, _            'memorizzo i tempi inviati dalla saldatrice durante la saldatura, ognuno seguito da un separatore
        "punti_temperatura": DBUtils.DB_TEXT, _        'memorizzo le temperature inviate dalla saldatrice durante la saldatura, ognuna seguita da un separatore
        "punti_pressione": DBUtils.DB_TEXT), _        'memorizzo le pressioni inviate dalla saldatrice durante la saldatura, ognuna seguita da un separatore
        "id")

    
    End If
    
    
    Provider.Initialize
    
    '*************************************************
    'For crashlytics
    Dim context As JavaObject 'depends on JavaObject
    context.InitializeContext
    CL.Initialize(context)
    '*************************************************
    
End Sub

Sub Service_Start (StartingIntent As Intent)

End Sub

Sub Service_Destroy

End Sub
 

Erel

Administrator
Staff member
Licensed User
File.DirInternal is the safest folder to use.

There are some cases where the secondary storage will not be available. You can test whether File.ExternalWritable is true or not.

It is also possible that there is no space left on the device. In that case there is nothing that you can do.
 

PierPaduan

Active Member
Licensed User
File.DirInternal is the safest folder to use.

There are some cases where the secondary storage will not be available. You can test whether File.ExternalWritable is true or not.

It is also possible that there is no space left on the device. In that case there is nothing that you can do.
Do you mean to do this way:
B4X:
    'SafeDirDefExt = rp.GetSafeDirDefaultExternal("")
    If File.ExternalWritable Then
        SafeDirDefExt = rp.GetSafeDirDefaultExternal("")
    Else
        SafeDirDefExt = File.DirInternal
    End If
 

Erel

Administrator
Staff member
Licensed User
Better:
B4X:
Dir = File.DirInternal
That is unless you have a special reason to use the secondary storage.
 
Top