Android Question [SQL] How to program when I have 1 db,but I have many tables.

Theera

Well-Known Member
Licensed User
Longtime User
Refer to this
I have tried to study dbutils example,I have customers.db which has RoomTable,GuestTable ,and RentTable.
What is Object should first be initialized?
How I code this line as below:
DBUtils.InsertMaps(Starter.SQL1,"RoomTable", ListOfMaps)

I have the written log as below
Logger connected to: HUAWEI LDN-LX2
--------- beginning of system
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (business) Create, isFirst = true **
** Activity (business) Resume **
** Activity (business) Pause, UserClosed = false **
** Activity (newguest) Create, isFirst = true **
** Activity (newguest) Resume **
21:19:17
Logger connected to: HUAWEI LDN-LX2
--------- beginning of system
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (business) Create, isFirst = true **
** Activity (business) Resume **
** Activity (business) Pause, UserClosed = false **
** Activity (newguest) Create, isFirst = true **
** Activity (newguest) Resume **
21:19:17
dbutils_insertmaps (java line: 588)
java.lang.RuntimeException: Object should first be initialized.
at anywheresoftware.b4a.sql.SQL.checkNull(SQL.java:55)
at anywheresoftware.b4a.sql.SQL.BeginTransaction(SQL.java:277)
at b4a.npsoft.millionaireresort.dbutils._insertmaps(dbutils.java:588)
at b4a.npsoft.millionaireresort.newguest._addentry(newguest.java:433)
at b4a.npsoft.millionaireresort.newguest._button1_click(newguest.java:488)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:6291)
at android.view.View$PerformClick.run(View.java:24931)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:101)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7529)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
 
Last edited:

eps

Expert
Licensed User
Longtime User
Theera, can you share any code? and if hitting these sorts of errors I usually generate the code in debug and get the B4A line of code which is erroring.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
From Erel’s example:
B4X:
    Dim ListOfMaps As List
    ListOfMaps.Initialize
    For i = 1 To 40
        Dim m As Map
        m.Initialize
        m.Put("Id", Id)
        m.Put("First Name", "John")
        m.Put("Last Name", "Smith" & i)
        ListOfMaps.Add(m)
    Next
    DBUtils.InsertMaps(SQL, "Students", ListOfMaps)
Without seeing your code, I only can guess you missed the line to initialize the List.
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
I copy Erel's code and change some code for my code. The different is my SQL database's tables are created by the third party( I didn't set index). When I run app. It show me "Object should first be initialized." I don't understand what something be wrong.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I copy Erel's code and change some code for my code. The different is my SQL database's tables are created by the third party( I didn't set index). When I run app. It show me "Object should first be initialized." I don't understand what something be wrong.
Upload a small project which shows the issue
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
B4X:
Sub Button1_Click
    DaysOfStay=StrUtil.NumOfDaysBetween(Date1,Date2)
    Dim kvs As KeyValueStore
    Dim xui As XUI
    xui.SetDataFolder("kvs")
    kvs.Initialize(xui.DefaultFolder, "kvs.dat")
    kvs.Put("time", DateTime.Now)
     'fetch this value
    Log(DateTime.Time(kvs.Get("time")))
    
    ToastMessageShow(DaysOfStay & " คืน", False)
    StartActivity (Business)
    'Use the database in the writable  location
    
    DBUtils.CopyDBFromAssets("CustomersDB.db")
    AddEntry
    
End Sub

Sub AddEntry
    Dim ListOfMaps As List
    ListOfMaps.Initialize
        
        Dim m As Map
        m.Initialize
        m.Put("RoomNo",Business.RoomNo)
        m.Put("PriceRoom", Business.PriceRoom)
        m.Put("VIPPriceRoom", (90/100)*Business.PriceRoom)
        ListOfMaps.Add(m)
    
    DBUtils.InsertMaps(Starter.SQL1,"RoomTable", ListOfMaps)
    
End Sub
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
?? This is not a export of a working project. With errors or not.

How should one compare the code you posted to check what is wrong if we do not have the database you used.

Good luck; i´m out
I never use SQL coding before. I have just test to insert only RoomTable. My error is below:
B4X:
Logger connected to: HUAWEI LDN-LX2
--------- beginning of system
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (business) Create, isFirst = true **
** Activity (business) Resume **
** Activity (business) Pause, UserClosed = false **
** Activity (newguest) Create, isFirst = true **
** Activity (newguest) Resume **
21:19:17
Logger connected to: HUAWEI LDN-LX2
--------- beginning of system
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (business) Create, isFirst = true **
** Activity (business) Resume **
** Activity (business) Pause, UserClosed = false **
** Activity (newguest) Create, isFirst = true **
** Activity (newguest) Resume **
21:19:17
dbutils_insertmaps (java line: 588)
java.lang.RuntimeException: Object should first be initialized.
at anywheresoftware.b4a.sql.SQL.checkNull(SQL.java:55)
at anywheresoftware.b4a.sql.SQL.BeginTransaction(SQL.java:277)
at b4a.npsoft.millionaireresort.dbutils._insertmaps(dbutils.java:588)
at b4a.npsoft.millionaireresort.newguest._addentry(newguest.java:433)
at b4a.npsoft.millionaireresort.newguest._button1_click(newguest.java:488)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:6291)
at android.view.View$PerformClick.run(View.java:24931)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:101)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7529)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
Ok Thank for everybody. I think I found my answer in this video.
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
Upvote 0
Top