the database is not recognized! help!

mauri74doc

Member
Licensed User
Longtime User
Hello to all. I have a big problem that I can not rosolvere, so I appealed to the availability of the community. My little project I'm working on (now discontinued for the problem we now explain) the risk of crashing already in the bud -> Unfortunately the problem is that the application does not work as it continues to give me error on the recognition of the database, useful for the development the application itself. For completeness, I did what was recommended (ie to load the db from the keys on the bottom right), but when I launch the debug, the line "dbcursor DBSql.ExecQuery = (" SELECT * FROM table ") is highlighted in yellow the line refers to the db and the emulator I get the words "Program paused online: 45 dbcursor DBSql.ExecQuery = (" SELECT * FROM table ")." I'm going crazy and especially the work is interrupted!
 

klaus

Expert
Licensed User
Longtime User
Without sseing your project it is imossible to help you !
Post your project with the db file as a zip file (IDE menu Files / Export As Zip).
A db file cannot be accessed in the File.DieAssets folder.
Did you have a look at the SQL chapter in the User's Guide ?

Best regards.
 
Upvote 0

mauri74doc

Member
Licensed User
Longtime User
'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim id As Int = 0
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 cmd_entra As Button
Dim lbl_benvenuto As Label
Dim Button2 As Button
Dim Button3 As Button
Dim Button4 As Button
Dim cmd_Back1 As Button
Dim cmd_casa As Button
Dim cmd_igene As Button
Dim cmd_viaggio As Button
Dim Cmd_casaPavimento As Button
Dim cmd_ApriFoto As Button
Dim cmd_ApriVideo As Button
Dim Label1 As Label
Dim Label2 As Label
Dim tipo As Byte = 0
Dim DBSql As SQL
Dim DBCursor As Cursor
Dim ImageView1 As ImageView
Dim Button1 As Button

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")
Activity.LoadLayout("main")
DBSql.Initialize(File.DirInternal,"pippo.db",True)

eseguiquery
End Sub

Sub eseguiquery

DBCursor = DBSql.ExecQuery("SELECT * FROM Tabella")
DBCursor.Close

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub cmd_entra_Click
Activity.RemoveAllViews
Activity.LoadLayout("menuprincipale")
End Sub


Sub cmd_casa_Click
Activity.RemoveAllViews
Activity.LoadLayout("casa_menu")
tipo = 1
End Sub
Sub Cmd_casaPavimento_Click
Activity.RemoveAllViews
Activity.LoadLayout("testo")
End Sub

Sub cmd_ApriVideo_Click

End Sub
Sub cmd_ApriFoto_Click

End Sub
Sub ImageView1_Click
If tipo = 1 Then
Activity.RemoveAllViews
Activity.LoadLayout("casa_menu")
Else If tipo = 2 Then
'continuare a inserire gli indirizzamenti alle altre pagine
End If
End Sub
 
Upvote 0

mauri74doc

Member
Licensed User
Longtime User
this in my project:

'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim id As Int = 0
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 cmd_entra As Button
Dim lbl_benvenuto As Label
Dim Button2 As Button
Dim Button3 As Button
Dim Button4 As Button
Dim cmd_Back1 As Button
Dim cmd_casa As Button
Dim cmd_igene As Button
Dim cmd_viaggio As Button
Dim Cmd_casaPavimento As Button
Dim cmd_ApriFoto As Button
Dim cmd_ApriVideo As Button
Dim Label1 As Label
Dim Label2 As Label
Dim tipo As Byte = 0
Dim DBSql As SQL
Dim DBCursor As Cursor
Dim ImageView1 As ImageView
Dim Button1 As Button

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")
Activity.LoadLayout("main")
DBSql.Initialize(File.DirInternal,"pippo.db",True)

eseguiquery
End Sub

Sub eseguiquery

DBCursor = DBSql.ExecQuery("SELECT * FROM Tabella")
DBCursor.Close

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub cmd_entra_Click
Activity.RemoveAllViews
Activity.LoadLayout("menuprincipale")
End Sub


Sub cmd_casa_Click
Activity.RemoveAllViews
Activity.LoadLayout("casa_menu")
tipo = 1
End Sub
Sub Cmd_casaPavimento_Click
Activity.RemoveAllViews
Activity.LoadLayout("testo")
End Sub

Sub cmd_ApriVideo_Click

End Sub
Sub cmd_ApriFoto_Click

End Sub
Sub ImageView1_Click
If tipo = 1 Then
Activity.RemoveAllViews
Activity.LoadLayout("casa_menu")
Else If tipo = 2 Then
'continuare a inserire gli indirizzamenti alle altre pagine
End If
End Sub
 
Upvote 0

mauri74doc

Member
Licensed User
Longtime User
this is my project:

'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim id As Int = 0
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 cmd_entra As Button
Dim lbl_benvenuto As Label
Dim Button2 As Button
Dim Button3 As Button
Dim Button4 As Button
Dim cmd_Back1 As Button
Dim cmd_casa As Button
Dim cmd_igene As Button
Dim cmd_viaggio As Button
Dim Cmd_casaPavimento As Button
Dim cmd_ApriFoto As Button
Dim cmd_ApriVideo As Button
Dim Label1 As Label
Dim Label2 As Label
Dim tipo As Byte = 0
Dim DBSql As SQL
Dim DBCursor As Cursor
Dim ImageView1 As ImageView
Dim Button1 As Button

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")
Activity.LoadLayout("main")
DBSql.Initialize(File.DirInternal,"pippo.db",True)

eseguiquery
End Sub

Sub eseguiquery

DBCursor = DBSql.ExecQuery("SELECT * FROM Tabella")
DBCursor.Close

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub cmd_entra_Click
Activity.RemoveAllViews
Activity.LoadLayout("menuprincipale")
End Sub


Sub cmd_casa_Click
Activity.RemoveAllViews
Activity.LoadLayout("casa_menu")
tipo = 1
End Sub
Sub Cmd_casaPavimento_Click
Activity.RemoveAllViews
Activity.LoadLayout("testo")
End Sub

Sub cmd_ApriVideo_Click

End Sub
Sub cmd_ApriFoto_Click

End Sub
Sub ImageView1_Click
If tipo = 1 Then
Activity.RemoveAllViews
Activity.LoadLayout("casa_menu")
Else If tipo = 2 Then
'continuare a inserire gli indirizzamenti alle altre pagine
End If
End Sub
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Why do yo post 3 times the same post ?
You should remove 2 of them.

Why didn't you post your project as a zip file as requested.
With the project we could test it in the same conditions as you do and find much easier where the problem is.

When posting code you should use code tags [ code ] [ /code ] without the spaces or use the # button.

A few points:
- Declare Dim DBCursor As Cursor in Process_Globals and not in Globals.
- Initialize DBSql.Initialize(File.DirInternal,"pippo.db",True) with FirstTime = True:
B4X:
If FirstTime Then
    DBSql.Initialize(File.DirInternal,"pippo.db",True)
End If
- What's the complete error message ?

Best regards.
 
Upvote 0

mauri74doc

Member
Licensed User
Longtime User
I'm sorry for the repetition. was my fault. I tried to do as you suggested/ recommended, but nothing changes. continues to give me error on line 46 of my project: I will highlight in yellow the line 46 (dbcursor DBSql.ExecQuery = ("SELECT * FROM tabella")) and then the emulator comes this statement: "program paused on line: 46 dbcursor DBSql.ExecQuery = ("SELECT * FROM tabella".
Can you help me?
Thanks for your time!
 

Attachments

  • progetto_mauri.zip
    7.8 KB · Views: 185
Upvote 0

abner69

Member
Licensed User
Longtime User
The Fix..

Mauri,

the problem was that you were not copying your db to the dirinternal as Klaus instructed. Also, you had pippo.db in your example, but the db has a name of pippo (without the db).

Also, you might want to read up on the cursor.. and how to process after..

I modified your example...I added a routine for copying your database, and expanded upon the db/cursor control for sqlite.. take a look, and let me know if you have any questions..

...Pablo
 

Attachments

  • prova_pablo.zip
    8.4 KB · Views: 231
Upvote 0

mauri74doc

Member
Licensed User
Longtime User
Hello Pablo and Klaus. I tried to run the program: runs! But the line 91 is highytlighted in yellow the following statement "activity.loadlayout ("testo") when i run the emulator (4.1 for android). In the emulator, procedeing in the navigation of the application, leave a message "program.paused on line:91 Activity.LoadLayout("testo"). Is it normal?? Could you still help me?
Thanks!!
 
Upvote 0

mauri74doc

Member
Licensed User
Longtime User
Hello! In my application I have a designer with some buttons, the text of which must be filled in at run time. The data is read from a database and stored in a standard array. My problem is that I need to know if you can create, and if so how, a dynamic array for creating buttons at run time of the program. You can also insert images (jpg, png, bmp) as the background of the button in addition to the text?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
My problem is that I need to know if you can create, and if so how, a dynamic array for creating buttons at run time of the program.
Yes you can.
Something like this (not tested):
B4X:
Sub Globals
    Dim btnTest(10) As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Dim i As Int
    
    For i = 0 To 9
        btnTest(i).Initialize("bntTest")
        Activity.AddView(btnTest(i), 0, 10dip + 70dip, 150dip, 60dip)
        btnTest(i).Text = "Test " & i
        btnTest(i).Tag = i
        Dim bdw As BitmapDrawable
        bdw.Bitmap = LoadBitmap(File.DirAssets, "image" & i & ".png")
        btnTest(i).Background = bdw
    Next
End Sub

Sub btnTest_Click
    Dim btn As Button
    
    btn = Sender
    
    Select btn.Tag
    Case 0
        ' code for Button 0
    Case 1
        ' code for Button 1
    Case 2
    .
    .
    End Select
End Sub
Best regards.
 
Upvote 0
Top