Dear Forum
I am new with BA4 and i am building an app that search a product in a database. This is my code:
when i compile all things are correct but when search a product that does not exist i get the following error in debug mode.
Error occurred on line: 62 (Main)
android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
I am new with BA4 and i am building an app that search a product in a database. This is my code:
B4X:
#Region Project Attributes
#ApplicationLabel: Barcode Scan
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Public SQL1 As SQL
Public SQLDataBasePath As String
Public SQLDataBaseName 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.
Private TabStrip1 As TabStrip
Private CodeBarreEditText As EditText
Private EffacerButton As Button
Private RechercheButton As Button
Private RefEditText As EditText
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")
'This is the program entry point.
'This is a good place to load resources that are not specific to a single activity.
SQLDataBasePath = File.DirRootExternal
SQLDataBaseName = "inventaire.db"
'check if the database already exists
If File.Exists(SQLDataBasePath, SQLDataBaseName) = True Then
'if yes initialize it
SQL1.Initialize(SQLDataBasePath, SQLDataBaseName, True)
Else
'if no copy it
File.Copy(File.DirAssets, SQLDataBaseName, SQLDataBasePath, SQLDataBaseName)
'and initialize it
SQL1.Initialize(SQLDataBasePath, SQLDataBaseName, True)
End If
Activity.LoadLayout("Main")
TabStrip1.LoadLayout("Page1", "Scan")
TabStrip1.LoadLayout("Page2", "Affichage")
End Sub
Sub SearchEntry
Dim cursor1 As Cursor
'RefEditText.text = SQL1.ExecQuery("Select DES from articles WHERE COBA = " & CodeBarreEditText.Text)
cursor1 = SQL1.ExecQuery("Select * from articles WHERE COBA = " & CodeBarreEditText.Text)
cursor1.Position = 0
If cursor1.GetString("DES") == "" Then
Msgbox("ARTICLE INEXISTANT","AVERTISSEMENT")
Else
RefEditText.text = cursor1.GetString("DES")
End If
cursor1.Close
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub TabStrip1_PageSelected (Position As Int)
End Sub
Sub CleanEntry
CodeBarreEditText.Text = ""
RefEditText.text = ""
End Sub
Sub RechercheButton_Click
SearchEntry
End Sub
Sub EffacerButton_Click
CleanEntry
End Sub
Error occurred on line: 62 (Main)
android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0