Android Question It crashes and i cannot see book cover

Enthousiastic

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
#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.
'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)
Activity.LoadLayout("main")
If FirstTime Then
CopyDBIfNeeded("rbbook.db")
sql.Initialize( File.DirDefaultExternal, "rbbook.db", False)
End If

Activity.LoadLayout("main")


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
Data.Initialize
' Dim rs As ResultSet = sql.ExecQuery("SELECT BId as [Α/Α],ISBN,Code as
B4X:
,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")
       
       
       
        Data.Add(row)
    Loop
    rs.Close
    B4XTable1.SetData(Data)
    For i = 1 To FlagsColumn.CellsLayouts.Size - 1
        Dim pnl As B4XView = FlagsColumn.CellsLayouts.Get(i)
        Dim iv As ImageView
        iv.Initialize("")
        pnl.AddView(iv, 5dip, 5dip, FlagsColumn.Width - 10dip, B4XTable1.RowHeight - 10dip)
    Next
   
   
   
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")
           
        Else
            'empty row
            iv.SetBitmap(Null)
        End If
    Next
   
   
   
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
 

DonManfred

Expert
Licensed User
Your post is HARD to read... Please use Code tags when posting code.

It crashes; with WHICH error? Should we guess it?

Please post the full error.
 
Last edited:
Upvote 0

Enthousiastic

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(AbsObjectWrapper.java:50)
at anywheresoftware.b4a.objects.B4XViewWrapper.GetView(B4XViewWrapper.java:298)
at b4a.example.main._b4xtable1_dataupdated(main.java:504)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1068)
at anywheresoftware.b4a.keywords.Common.CallSubNew(Common.java:1015)
at b4a.example.b4xtable$ResumableSub_ImplUpdateDataFromQuery.resume(b4xtable.java:1675)
at anywheresoftware.b4a.keywords.Common$13.run(Common.java:1690)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
 

Attachments

  • RBBook.zip
    10.8 KB · Views: 71
Upvote 0

asales

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:
java.io.FileNotFoundException: rbbook.db
Check again and upload a new project.
 
Upvote 0

DonManfred

Expert
Licensed User
Upvote 0
Top