Android Question It crashes and i cannot see book cover


Active Member
Licensed User
I wrote the following code like flags example, but it crashes and i cannot see book cover photo . What i've done wrong PLEASE HELP !!!

Region Project Attributes
#ApplicationLabel: MyRBBooks
#VersionCode: 1
'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.
'Dim DBFileName As String : DBFileName = "rbbook.db"
'Dim DBFileDir As String : DBFileDir = File.DirDefaultExternal
'Dim DBTableName As String : DBTableName = "tblrbook"

Private sql As SQL

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 B4XTable1 As B4XTable
Private FlagsColumn As B4XTableColumn
Private xui As XUI

End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
sql.Initialize( File.DirDefaultExternal, "rbbook.db", False)
End If


Activity.Title=" BOOKS LIST (GRID)"

B4XTable1.AddColumn("BId", B4XTable1.COLUMN_TYPE_NUMBERS)
B4XTable1.AddColumn("ISBN", B4XTable1.COLUMN_TYPE_TEXT)
B4XTable1.AddColumn("Code", B4XTable1.COLUMN_TYPE_TEXT)
B4XTable1.AddColumn("RBMDate", B4XTable1.COLUMN_TYPE_TEXT)
B4XTable1.AddColumn("Category", B4XTable1.COLUMN_TYPE_TEXT)
B4XTable1.AddColumn("FTitle", B4XTable1.COLUMN_TYPE_TEXT)
B4XTable1.AddColumn("FSubTitle", B4XTable1.COLUMN_TYPE_TEXT)
B4XTable1.AddColumn("GTitle", B4XTable1.COLUMN_TYPE_TEXT)
B4XTable1.AddColumn("GSubTitle", B4XTable1.COLUMN_TYPE_TEXT)
B4XTable1.AddColumn("Authors", B4XTable1.COLUMN_TYPE_TEXT)
B4XTable1.AddColumn("Publisher", B4XTable1.COLUMN_TYPE_TEXT)
B4XTable1.AddColumn("Cover", B4XTable1.COLUMN_TYPE_TEXT)
B4XTable1.AddColumn("CovPhoto", B4XTable1.COLUMN_TYPE_TEXT)
B4XTable1.AddColumn("BCovPhoto", B4XTable1.COLUMN_TYPE_TEXT)


' FlagsColumn = B4XTable1.AddColumn("COVER PICTURE", B4XTable1.COLUMN_TYPE_TEXT)

FlagsColumn = B4XTable1.AddColumn("CovPhoto", B4XTable1.COLUMN_TYPE_TEXT)
FlagsColumn.Width = 60dip
FlagsColumn.Searchable = False
FlagsColumn.Sortable = False
B4XTable1.RowHeight = 60dip
'B4XTable1.AddColumn("Α/Α", B4XTable1.COLUMN_TYPE_NUMBERS).Width = 50dip
'B4XTable1.AddColumn("ISBN", B4XTable1.COLUMN_TYPE_TEXT).Width = 200dip
'B4XTable1.AddColumn("CODE", B4XTable1.COLUMN_TYPE_TEXT).Width = 90dip
'B4XTable1.AddColumn("MONTH/YEAR", B4XTable1.COLUMN_TYPE_TEXT).Width = 90dip
'B4XTable1.AddColumn("CATEGORY", B4XTable1.COLUMN_TYPE_TEXT).Width = 90dip
'B4XTable1.AddColumn("FOR TITLE", B4XTable1.COLUMN_TYPE_TEXT).Width = 80dip
'B4XTable1.AddColumn("FOR SUBTITLE", B4XTable1.COLUMN_TYPE_TEXT).Width = 300dip
'B4XTable1.AddColumn("OR TITLE", B4XTable1.COLUMN_TYPE_TEXT).Width = 300dip
'B4XTable1.AddColumn("OR SUBTITLE", B4XTable1.COLUMN_TYPE_TEXT).Width = 300dip
'B4XTable1.AddColumn("AUTHORS", B4XTable1.COLUMN_TYPE_TEXT).Width = 300dip
'B4XTable1.AddColumn("PUBLISHER", B4XTable1.COLUMN_TYPE_TEXT).Width = 250dip
'B4XTable1.AddColumn("PHOTO", B4XTable1.COLUMN_TYPE_TEXT).Width = 150dip
'B4XTable1.AddColumn("FRONT COVER", B4XTable1.COLUMN_TYPE_TEXT).Width = 150dip
'B4XTable1.AddColumn("BACK COVER", B4XTable1.COLUMN_TYPE_TEXT).Width = 150dip
Dim Data As List
' Dim rs As ResultSet = sql.ExecQuery("SELECT BId as [Α/Α],ISBN,Code as
,RBMDate as [MONTH/YEAR],Category as [CATEGORY],FTitle as [FOR TITLE],FSubTitle as [FOR SUBTITLE],GTitle as [OR TITLE],GSubTitle as [OR SUBTITLE] ,Authors as [AUTHORS], Publisher as [PUBLISHER],Cover as [PHOTO],CovPhoto as [FRONT COVER],BCovPhoto as [BACK COVER] FROM " & DBTableName)
    Dim rs As ResultSet = sql.ExecQuery("SELECT BId ,ISBN,Code ,RBMDate ,Category ,FTitle ,FSubTitle ,GTitle ,GSubTitle , Authors , Publisher ,Cover ,CovPhoto ,BCovPhoto  FROM tblrbook")
    Do While rs.NextRow
        Dim row(14) As Object
        row(0) = rs.GetDouble("BId")
        row(1) = rs.GetString("ISBN")
        row(2) = rs.GetString("Code")
        row(3) = rs.GetString("RBMDate")
        'Some of the fields are Null. We need to convert them to empty strings:
        '    If row(2) = Null Then row(2) = ""
        row(4) = rs.GetString("Category")
        row(5) = rs.GetString("FTitle")
        row(6) = rs.GetString("FSubTitle")
        row(7) = rs.GetString("GTitle")
        row(8) = rs.GetString("GSubTitle")
        row(9) = rs.GetString("Authors")
        row(10) = rs.GetString("Publisher")
        row(11) = rs.GetString("Cover")
        row(12) = rs.GetString("CovPhoto")
        row(13) = rs.GetString("BCovPhoto")
    For i = 1 To FlagsColumn.CellsLayouts.Size - 1
        Dim pnl As B4XView = FlagsColumn.CellsLayouts.Get(i)
        Dim iv As ImageView
        pnl.AddView(iv, 5dip, 5dip, FlagsColumn.Width - 10dip, B4XTable1.RowHeight - 10dip)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub B4XTable1_DataUpdated
    For i = 0 To B4XTable1.VisibleRowIds.Size - 1
        Dim RowId As Long = B4XTable1.VisibleRowIds.Get(i)
        Dim pnl As B4XView = FlagsColumn.CellsLayouts.Get(i + 1) '+1 because the first cell is the header
        Dim iv As B4XView = pnl.GetView(1) 'ImageView will be the 2nd child of the panel. The built-in label is the first.
        If RowId > 0 Then
            Dim row As Map = B4XTable1.GetRow(RowId)
            iv.SetBitmap(xui.LoadBitmapResize(File.DirAssets, row.Get("CovPhoto") & ".jpg", iv.Width, iv.Height, True))
            Log("Photo is " & row.Get("CovPhoto") & ".jpg")
            'empty row
        End If
End Sub
Sub CopyDBIfNeeded (Filename As String)
    If File.Exists( File.DirDefaultExternal, Filename) = False Then
        File.Copy(File.DirAssets, Filename,  File.DirDefaultExternal, Filename)
    End If
End Sub


Active Member
Licensed User
Hello again , in my previouw thread (it crashes and i cannot see the book cover image like flags example ) the error log text is , can you help me ? :

*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
main_b4xtable1_dataupdated (java line: 504)
java.lang.RuntimeException: Object should first be initialized (View).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(
at anywheresoftware.b4a.objects.B4XViewWrapper.GetView(
at b4a.example.main._b4xtable1_dataupdated(
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(
at anywheresoftware.b4a.keywords.Common.CallSub4(
at anywheresoftware.b4a.keywords.Common.CallSubNew(
at b4a.example.b4xtable$ResumableSub_ImplUpdateDataFromQuery.resume(
at anywheresoftware.b4a.keywords.Common$
at android.os.Handler.handleCallback(
at android.os.Handler.dispatchMessage(
at android.os.Looper.loop(
at java.lang.reflect.Method.invoke(Native Method)



Well-Known Member
Licensed User
I check your project and I don't find the rbbook.db file in the Files folder.
Without this file I get this error:
B4X: rbbook.db
Check again and upload a new project.