Android Question SQLite does not work 'Initialize'

MichalK73

Well-Known Member
Licensed User
Longtime User
Hello.

I have a strange problem.
Trying to connect SQLite database and the program displays a Java error.

HTML: Copy
Copying updated assets files (1)
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 40 (Main)
android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
    at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
    at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:207)
    at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:191)
    at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
    at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
    at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
    at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:806)
    at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:791)
    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:669)
    at anywheresoftware.b4a.sql.SQL.Initialize(SQL.java:37)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:742)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at com.tarot.main.afterFirstLayout(main.java:102)
    at com.tarot.main.access$000(main.java:17)
    at com.tarot.main$WaitForLayout.run(main.java:80)
    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:5466)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:114)
** Activity (main) Resume **

The database file is located in the 'Files' and performs:
Code: Copy
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Activity.LoadLayout("main")
    SQL1.Initialize(File.DirAssets, "date.db", True) 'not working :(
    ImageView1.Bitmap=LoadBitmap(File.DirAssets,"diabel.jpg") 'working fine
End Sub
   
End Sub

The same database without problems opens in SQLite Viewer (base placed on sdcard), just as jpg image files attached to your 'Files' work properly.

What am I doing wrong ??
 
The database must be in the File folder in your project and see this and uninstall the app and reinstall.

Code: Copy
    Dim ruta As String
    If File.ExternalWritable Then
        ruta = File.DirDefaultExternal
    Else
        ruta = File.DirInternal
    End If
    If File.Exists(ruta, "date.db") = False Then
        File.Copy(File.DirAssets, "date.db", ruta, "date.db")
    End If
       
SQL1
.Initialize(ruta, "date.db", True)
 
Upvote 0
The database must be in the File folder in your project
Not necessarily.
It is possible to create the databasefile. But it still needs to be initialized.

Code: Copy
If File.Exists(File.DirInternal, "date.db") = False Then
        Main.sql1.Initialize(File.DirInternal, "date.db", True)
Else If Main.sql1.IsInitialized = False Then
        Main.sql1.Initialize(File.DirInternal, "date.db", True)
End If
 
Upvote 0
The database must be in the File folder in your project and see this and uninstall the app and reinstall.

Code: Copy
    Dim ruta As String
    If File.ExternalWritable Then
        ruta = File.DirDefaultExternal
    Else
        ruta = File.DirInternal
    End If
    If File.Exists(ruta, "date.db") = False Then
        File.Copy(File.DirAssets, "date.db", ruta, "date.db")
    End If
      
SQL1
.Initialize(ruta, "date.db", True)

Thanks. Its works good.
 
Upvote 0

Similar Threads

Replies
11
Views
5K
  • Article Article
Android Code Snippet Using SQLite
Replies
2
Views
3K
  • Question Question
Android Question SQLite Won't Sort
Replies
16
Views
7K
Back
Top