Android Question error while trying to load converation

Makumbi

Well-Known Member
Licensed User
B4X:
Sub spnFirstName_ItemClick (Position As Int, Value As Object)
    Add_Conversation(True,"Makumbi","Hi all! Here is a simple message example")
    
'    End If
End Sub

B4X:
[]
3
** Activity (main) Pause, UserClosed = false **
** Activity (simplechat) Create, isFirst = true **
** Activity (simplechat) Resume **
** Activity (simplechat) Pause, UserClosed = false **
** Activity (sendsms) Create, isFirst = true **
** Activity (sendsms) Resume **
no extras
java.lang.StackOverflowError: stack size 8MB
    at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:7352)
    at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:7354)
    at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:7354)
    at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:7354)
    at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:7354)
    at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:7354)
    at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:7354)
    at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:7354)
    at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:7354)
    at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:7354)
    at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:7354)
    at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:7354)
    at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:7354)
    at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:7354)
    at android.view.ViewGroup.resetResolvedLayoutDirection(ViewGroup.java:7354)


B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    
    Activity.LoadLayout("2")
    Engine.Initialize(Activity)
    'Engine.Initialize(Me)
    'bc.Initialize(300, 300)
    If IsConnectedToInternet=True Then
        InitSpinners
    
    
    Else
        MsgboxAsync("Error Connecting to the Server Please Check Your Internet Connection","Server Error")

        Return
        End If
End Sub


Private Sub client_MessageArrived (Topic As String, Payload() As Byte)
    Dim receivedObject As Object = serializator.ConvertBytesToObject(Payload)

Dim m As Message = receivedObject
    CallSub2(chats, "NewMessage", m)
    
End Sub
    
    
Private Sub CreateItem(Width As Int, Title As String, Image As String, Content As String,senderx As String) As Panel
    Dim p As B4XView = xui.CreatePanel("")
    Dim height As Int = 280dip
    If GetDeviceLayoutValues.ApproximateScreenSize < 4.5 Then height = 310dip
    p.SetLayoutAnimated(0, 0, 0, Width, height)
    p.LoadLayout("Card2")
    
    lblTitle.Text = Title
    lblContent.Text = Content
    Label1.Text= senderx
    'SetColorStateList(lblContent, xui.Color_Red,lblContent.TextColor)
    SetColorStateList(lblAction1, xui.Color_LightGray, lblAction1.TextColor)
    SetColorStateList(lblAction2, xui.Color_LightGray, lblAction2.TextColor)
    ImageView1.SetBitmap(xui.LoadBitmapResize(File.DirAssets, Image, ImageView1.Width, ImageView1.Height, True))
    ScrollToLastItem
    Return p

End Sub

Private Sub ScrollToLastItem
    Sleep(50)
    If CLV1.Size > 0 Then
        If CLV1.sv.ScrollViewContentHeight > CLV1.sv.Height Then
            CLV1.ScrollToItem(CLV1.Size - 1)
        End If
    End If
End Sub

Sub SetColorStateList(Btn As Label,Pressed As Int,Enabled As Int)
    Dim States(2,1) As Int
    States(0,0) = 16842919    'Pressed
    States(1,0) = 16842910    'Enabled
    Dim CSL As JavaObject
    CSL.InitializeNewInstance("android.content.res.ColorStateList",Array(States,Array As Int(Pressed, Enabled)))
    Dim B1 As JavaObject = Btn
    B1.RunMethod("setTextColor",Array As Object(CSL))
End Sub
Private Sub CreateMessage(Body As String) As Byte()
    Dim m As Message
    m.Initialize
    m.Body = Body
    m.From = "currentName"
    Return serializator.ConvertObjectToBytes(m)
End Sub
Public Sub NewMessage(msg As Message)
    txtLogs.Text = $"${msg.From}: ${msg.Body}"$ & CRLF & txtLogs.Text
End Sub
Sub Activity_Resume
    If Starter.strBody="" Then
    Dim in As Intent = Activity.GetStartingIntent
    'If in.IsInitialized And in <> OldIntent Then
        'OldIntent = in
    Log(in.ExtrasToString)
        If in.HasExtra("Notification_Tag") Then
            Log("Activity started from notification. Tag: " & in.GetExtra("Notification_Tag"))
        'Log("Activity started from notification. Tag: " & in.GetExtra("Notification_Tag"))
        txtLogs.Text= in.GetExtra("Notification_Tag")
        'CallSub2(Sendsms, "SetText", Message.GetData.Get("title"))
        End If
        Else
    txtLogs.Text= Starter.strBody
    'lblBody.Text = Starter.strBody
    'CallSubDelayed2(ActivityA, ReceiveMsg, SelectedMsg)
    End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)
Activity.Finish
End Sub


Sub btnSend_Click
    
    If txtMessage.Text <> "" Then
        If    spnFirstName.SelectedItem ="Select from the List..." Then
            MsgboxAsync("You Must Select the Student Name. ", "SMIS")
            spnFirstName.RequestFocus
            Return
        End If
         CallSub2(Starter, "SendMessage", txtMessage.Text)
        txtLogs.Text = txtMessage.Text
        CreateMessage(txtMessage.Text)
        
        Else
    If    txtMessage.Text="" Then
            MsgboxAsync("You Must Enter Some Text To Countinue. ", "SMIS")
            txtMessage.RequestFocus
            Return
        End If
        
        
        'NewMessage
    End If
    
    'Dim j As HttpJob
    'j.Initialize("", Me)
            'j.Download($"http://kccug.com/KabojjaApp/RecieveSMS.ashx?customerId=${act}&s=${txtMessage.Text}&d=${DateTime.Date(l)& " "& DateTime.Time(now)}&id=${NewID}&ph=${phone}&f=${sx}"$ )
    
            
            Dim holdnbemail As String
            Dim rstnbemail As ResumableSub = Loadmessage(holdnbemail)
            Wait For(rstnbemail) Complete (Result As String)
            
            
            'Dim b As Beeper
            'b.Initialize(300, 500) '300 milliseconds, 500 hz
            'b.Beep
        MsgboxAsync("SMS Sent Successfully ", "SMIS")

    'Else
    'MsgboxAsync("Error Connecting to the Server Please Check Your Internet Connection","Server Error")

    Return
    
    
End Sub



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

    'GET IF IS LEFT OR RIGHT CHAT
    If leftChat Then
        pWhite.Left = margin
        lbNome.Gravity = Bit.Or(Gravity.LEFT,Gravity.CENTER_VERTICAL)
        txtMessage.Gravity = Bit.Or(Gravity.LEFT,Gravity.CENTER_VERTICAL)
    Else
        pWhite.Left = 100%x - messageSize - margin
        lbNome.Gravity = Bit.Or(Gravity.RIGHT,Gravity.TOP)
        txtMessage.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)
    txtMessage.Height =su.MeasureMultilineTextHeight(txtMessage,txtMessage.Text)
    txtMessage.Top = lbNome.Top + lbNome.Height
        
        
    'LATER GET THE CORRECT SIZE NEEDED WE APPLY THIS TO PANEL
    p.Height = lbNome.Height + txtMessage.Height + (internalYMargin * 2)
    pWhite.Height = lbNome.Height + txtMessage.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
    CLV1.Add(p,0)
    'CLV1.Add(CreateItem(CLV1.AsView.Width, $"Anouncement #${i}"$, bitmaps.Get(0), content &":"& Phonegb,senderb), Phonegb)
        
    
    'CLV1.AddTextItem($"Item ${i}"$, "")
    
End Sub

error occurs here
B4X:
    CLV1.Add(p,0)
 

Attachments

  • Screenshot_1586276532.png
    Screenshot_1586276532.png
    46.4 KB · Views: 35
Top