Android Question Error while loading records from spinner

Makumbi

Well-Known Member
Licensed User
below is the error please help thanks find attached a small project where the error is coming from
B4X:
sms: How will the work be marked?
Datesent: /Date(1588501226000)/
2
1588501225000
How will the work be marked?
IN
RVD
Error occurred on line: 262 (Getchats)
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
    at android.view.ViewGroup.addViewInner(ViewGroup.java:5034)
    at android.view.ViewGroup.addView(ViewGroup.java:4865)
    at android.view.ViewGroup.addView(ViewGroup.java:4837)
    at anywheresoftware.b4a.objects.PanelWrapper.AddView(PanelWrapper.java:65)
    at anywheresoftware.b4a.objects.B4XViewWrapper.AddView(B4XViewWrapper.java:305)
    at b4a.example3.customlistview._insertatimpl(customlistview.java:567)
    at b4a.example3.customlistview._insertat(customlistview.java:540)
    at b4a.example3.customlistview._add(customlistview.java:71)
    at b4a.example.getchats$ResumableSub_LoadMessages.resume(getchats.java:1177)
    at b4a.example.getchats._loadmessages(getchats.java:1074)
    at b4a.example.getchats._spnfirstname_itemclick(getchats.java:1335)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
this is where i select the spinner record
B4X:
Sub spnFirstName_ItemClick (Position As Int, Value As Object)
    'Starter.oSQL.ExecQuerySingleResult2("UPDATE tbl_Messages SET INflag='READ' WHERE INflag LIKE '%UNREAD%' and ChatClientName = ?", Array As String(spnFirstName.SelectedItem))
   
    clvMensagens.Clear
    LoadMessages(spnFirstName.SelectedItem)
    ScrollToLastItem
End Sub
error occurs here
B4X:
  Return p


B4X:
Sub Add_Conversation (leftChat As Boolean, name As String, message As String,Phonek As String) As Panel
   
    Private p As Panel
    p.Initialize("p")
    p.Visible = False
    Activity.AddView(p,margin,0,messageSize,5%Y)
    p.LoadLayout("Cardchats2")
    p.RemoveView
       
    'HERE WE ADD THE MESSAGE AND NAME TO LBNAME AND LBMESSAGE
    lbNome.Text = name
    lbMensagem.Text = message
    Phone.Text=Phonek
    Phone.Visible=False
       

    'GET IF IS LEFT OR RIGHT CHAT
    If leftChat Then
        pWhite.Left = margin
        lbNome.Gravity = Bit.Or(Gravity.LEFT,Gravity.CENTER_VERTICAL)
        lbMensagem.Gravity = Bit.Or(Gravity.LEFT,Gravity.CENTER_VERTICAL)
    Else
        pWhite.Left = 100%x - messageSize - margin
        lbNome.Gravity = Bit.Or(Gravity.RIGHT,Gravity.TOP)
        lbMensagem.Gravity = Bit.Or(Gravity.RIGHT,Gravity.TOP)
    End If
       
       
       
    'HERE WE GET THE MESSAGE AND NAME CHAT
    Private su As StringUtils
    lbNome.Top = 0 + internalYMargin
    lbNome.Height =su.MeasureMultilineTextHeight(lbNome,lbNome.Text)
    lbMensagem.Height =su.MeasureMultilineTextHeight(lbMensagem,lbMensagem.Text)
    lbMensagem.Top = lbNome.Top + lbNome.Height
       
       
    'LATER GET THE CORRECT SIZE NEEDED WE APPLY THIS TO PANEL
    p.Height = lbNome.Height + lbMensagem.Height + (internalYMargin * 2)
    pWhite.Height = lbNome.Height + lbMensagem.Height + (internalYMargin * 2)
   
   
   
   
    'HERE WE SET THE COLOR AND BORDER TO THE MESSAGE PANEL

   
    If border Then
        If leftChat Then
            Private cd As ColorDrawable
            cd.Initialize2(leftColor,5,borderWidth,borderColor)
            pWhite.Background = cd
        Else
            Private cd As ColorDrawable
            cd.Initialize2(rightColor,5,borderWidth,borderColor)
            pWhite.Background = cd
        End If
    Else
        If leftChat Then
            Private cd As ColorDrawable
            cd.Initialize2(leftColor,5,0,borderColor)
            pWhite.Background = cd
        Else
            Private cd As ColorDrawable
            cd.Initialize2(rightColor,5,0,borderColor)
            pWhite.Background = cd
        End If
    End If
   
   
   
   
       
       
    p.Visible = True
    'HERE WE ADD THE CONVERSATION PANEL WITH NAME AND MESSAGE TO CLV
   

    Try

        p.RemoveView
       
        clvMensagens.Add(p,p.Height)
        Return p
    Catch
        Log(LastException)
       
    End Try
End Sub
 

Attachments

  • Backup 1 2020-05-03 17.29.zip
    45.2 KB · Views: 253
Last edited:

LucaMs

Expert
Licensed User
Longtime User
I downloaded and tried to start your project, getting this error:

android.database.sqlite.SQLiteException: table tbl_Messagesdata has 8 columns but 6 values were supplied (Sqlite code 1): , while compiling: INSERT INTO tbl_Messagesdata VALUES ('NULL', '1', '0001','Makumbi','0782911364','Good moring sula'), (OS error - 2:No such file or directory)

You know what it means (number of table fields and data in your query don't match).

Please, correct and attach it again (use the menu File - Export As Zip)
 
Upvote 0

Makumbi

Well-Known Member
Licensed User
I downloaded and tried to start your project, getting this error:

android.database.sqlite.SQLiteException: table tbl_Messagesdata has 8 columns but 6 values were supplied (Sqlite code 1): , while compiling: INSERT INTO tbl_Messagesdata VALUES ('NULL', '1', '0001','Makumbi','0782911364','Good moring sula'), (OS error - 2:No such file or directory)

You know what it means (number of table fields and data in your query don't match).

Please, correct and attach it again (use the menu File - Export As Zip)

i have attached a new file thanks
 

Attachments

  • Backup 1 2020-05-04 05.55.zip
    44.8 KB · Views: 213
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
There are some wrong queries.

Use these as example:
B4X:
        oSQL.ExecNonQuery2("INSERT INTO tbl_Messagesdata VALUES (?,?,?,?,?,?,?,?)", Array(Null, DateTime.Now, "0001", "Makumbi", "0782911364", "Good moring sula", "IOFlag1", "INFlag1"))
        oSQL.ExecNonQuery2("INSERT INTO tbl_Messagesdata VALUES (?,?,?,?,?,?,?,?)", Array(Null, DateTime.Now, "0001", "Makumbi", "0782911364", "Arrivederci Roma", "IOFlag2", "INFlag2"))
        oSQL.ExecNonQuery2("INSERT INTO tbl_Messagesdata VALUES (?,?,?,?,?,?,?,?)", Array(Null, DateTime.Now, "0002", "Sula", "0782911555", "Good bye sula", "IOFlag3", "INFlag3"))
        oSQL.ExecNonQuery2("INSERT INTO tbl_Messagesdata VALUES (?,?,?,?,?,?,?,?)", Array(Null, DateTime.Now, "0002", "Sula", "0782911555", "Good morning sula", "IOFlag4", "INFlag4"))

Note: 8 question marks, 8 values.
 
Upvote 0

Makumbi

Well-Known Member
Licensed User
Do
There are some wrong queries.

Use these as example:
B4X:
        oSQL.ExecNonQuery2("INSERT INTO tbl_Messagesdata VALUES (?,?,?,?,?,?,?,?)", Array(Null, DateTime.Now, "0001", "Makumbi", "0782911364", "Good moring sula", "IOFlag1", "INFlag1"))
        oSQL.ExecNonQuery2("INSERT INTO tbl_Messagesdata VALUES (?,?,?,?,?,?,?,?)", Array(Null, DateTime.Now, "0001", "Makumbi", "0782911364", "Arrivederci Roma", "IOFlag2", "INFlag2"))
        oSQL.ExecNonQuery2("INSERT INTO tbl_Messagesdata VALUES (?,?,?,?,?,?,?,?)", Array(Null, DateTime.Now, "0002", "Sula", "0782911555", "Good bye sula", "IOFlag3", "INFlag3"))
        oSQL.ExecNonQuery2("INSERT INTO tbl_Messagesdata VALUES (?,?,?,?,?,?,?,?)", Array(Null, DateTime.Now, "0002", "Sula", "0782911555", "Good morning sula", "IOFlag4", "INFlag4"))

Note: 8 question marks, 8 values.
Please don't consider the insert of queries I disregarded them only consider the creation of the two tables because in the second attachment I disabled them I remained with only the create table and it works
 
Upvote 0

Makumbi

Well-Known Member
Licensed User
No, it works on your device because you already have the db in the internal directory.

hope this 3rd attachment is ok thank you for your precious time

i have also modifeied your query to have these fields as
B4X:
oSQL.ExecNonQuery2("INSERT INTO tbl_Messagesdata VALUES (?,?,?,?,?,?,?,?,?)", Array(Null, DateTime.Now, "0001", "Makumbi",  "Good moring sula", "IOFlag1", "INFlag1","0782911364","Father"))
      oSQL.ExecNonQuery2("INSERT INTO tbl_Messagesdata VALUES (?,?,?,?,?,?,?,?,?)", Array(Null, DateTime.Now, "0001", "Makumbi", "Arrivederci Roma", "IOFlag2", "INFlag2", "0782911364","Father"))
      oSQL.ExecNonQuery2("INSERT INTO tbl_Messagesdata VALUES (?,?,?,?,?,?,?,?,?)", Array(Null, DateTime.Now, "0002", "Sula", "Good bye sula", "IOFlag3", "INFlag3","0782911555","Mother"))
 

Attachments

  • Backup 1 2020-05-04 10.53.zip
    44.7 KB · Views: 228
Last edited:
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
ONE error was inside the Add_Conversation routine, which should (and does) return a panel (the clv element) which is then added to the clv but you add the panel itself within this routine and then again when the routine ends and returns the panel (see from line 249 of Add_Conversation).

There is another wrong query (number of fields and values).

I have eliminated a Sleep; if you want to use this, the routine that contains it (LoadMessages) must complete its work before the project continues, which means calling it differently: https://www.b4x.com/android/forum/threads/b4x-resumable-subs-sleep-wait-for.78601/#content
 

Attachments

  • 1.zip
    44.8 KB · Views: 248
Upvote 0
Top