Android Question Program Crash

Jiten Shah

Member
Licensed User
Dear All

I am new to Android & B4X both.

I have Android device M3 Mobile SM10 with laser barcode scanner built-in

Android Version : 4.3

When I am scanning the barcode through scanner my program crashed
log file is attached.

Barcode scan mode is Keyboard.

Jiten
 

Attachments

  • crash_log.txt
    58.9 KB · Views: 191

Jiten Shah

Member
Licensed User
This is part of activity code

B4X:
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: False
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

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 btnSave As Button
    Private btnSearch As Button
    Private Label3 As Label
    Private txtBarcode As EditText
    Private txtQty As EditText
    Private Label1 As Label
    Private lblDesc As Label
    Private Label2 As Label
    Private lblInfo As Label
    Private btnNewid As Button
    Dim current_id As Long = 0
    Dim current_date As Long  = 0
    Private lblExpiryDate As Label
    Private btnSyncItem As Button
    Private lblMsg As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("item_capture")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Activity_KeyPress (KeyCode As Int) As Boolean
    If KeyCode = KeyCodes.KEYCODE_BACK Then
        If Msgbox2("Are you sure you want to close", "", "Yes", "", "No", Null) = DialogResponse.NEGATIVE Then
            Return True
        End If
    End If
    Return False
End Sub

Sub txtBarcode_EnterPressed
    Dim m As EditText = Sender
    search_item(m.Text)
End Sub

Sub btnSearch_Click
    search_item(txtBarcode.Text)
End Sub

Sub display_items(item_list As List, is_scale_barcode As Boolean, weight As Double)
    Dim m As Map
    Dim jlist As List
    Dim jmap As Map
       
    mod_gen.hide_keyboard()
   
    If is_scale_barcode = False Then
        jlist.Initialize()
        jmap.Initialize()
           
        Dim idx As Int = 0
        For Each m As Map In item_list
            Dim cs As CSBuilder
            cs.Initialize()
            cs.Append(mod_gen.format_long_number(m.Get("barcode")) & " | " )
            cs.Color(Colors.Yellow).Size(25).Append(m.Get("cf")).PopAll
            jlist.Add(cs)
            jmap.Put(idx, m)
            idx = idx +1
        Next
        idx = InputList(jlist, "Select", -1)
        If idx = DialogResponse.CANCEL Then
            Return
        End If
        m = jmap.Get(idx)
    Else
        m = item_list.Get(0)
        txtQty.Text = weight
    End If
       
    Dim cs As CSBuilder
    cs.Initialize()
    cs.Append("NAME:").Append(CRLF)
    cs.Color(Colors.Blue).Append(m.Get("item_name")).Append(CRLF).PopAll
    cs.Append("CODE:").Append(CRLF)
    cs.Color(Colors.Blue).Append(mod_gen.format_long_number(m.Get("barcode"))).PopAll.Append(" | ").PopAll
    cs.Append("PKG :")
    cs.Color(Colors.Yellow).Append(m.Get("cf")).PopAll
    lblDesc.Text = cs
       
    lblExpiryDate_Click
       
    txtQty.Tag = m.Get("id")
    txtQty.RequestFocus
    mod_gen.show_keyboard(txtQty)
   
End Sub

Sub search_item(barcode As String)
    If barcode.Length() = 0 Then
        Msgbox("Barcode cannot be empty", "Input-Error")
        Return
    End If
   
    Dim is_scale_barcode As Boolean = False
    Dim weight As Double
    Dim new_barcode As String
    Dim rdata As Map = mod_gen.get_scale_barcode(barcode)
    If rdata.Get("success") = True Then
        new_barcode = rdata.get("barcode")
        weight      = rdata.get("weight")
        is_scale_barcode = True
    Else
        new_barcode = barcode
    End If
   
    'search local sqlite db
    Dim found_in_local As Boolean = False
    Dim a_list As List = search_item_local(new_barcode)
    If a_list.Size > 0 Then
        display_items(a_list, is_scale_barcode, weight)
        lblMsg.Text = "Item Found In Local"
        Return
    End If
   
    'search server if not found in local db
    Dim job As HttpJob = mod_gen.CreateHttpJob("item2", CreateMap("barcode":new_barcode), Me)
    Wait for (job) jobdone(j As HttpJob)
    If job.Success = True Then
        Dim x As JSONParser
        x.Initialize(job.GetString)
        Dim l As List = x.NextArray()
        If l.Get(0) = False Then
            Dim a As Beeper
            a.Initialize(100, 500)
            a.Beep()
        Else
            Dim a_list As List = l.Get(1)
            For Each m As Map In a_list
                m.Put("item_name", m.Get("nm"))
                m.Put("item_id", m.Get("id"))
            Next
            display_items(a_list, is_scale_barcode, weight)           
            lblMsg.Text = "Item Found In Server"
            If found_in_local = False Then
                Dim sql As String
                sql = $"
                insert into imast(item_id, item_name, cf, barcode, parent_id)
                values(?, ?, ?, ?, ?)
                "$
                mod_gen.db_con.BeginTransaction
                For Each m As Map In a_list
                    Dim xlist As List
                    xlist.Initialize()
                    xlist.Add(m.Get("item_id"))
                    xlist.Add(m.Get("item_name"))
                    xlist.Add(m.Get("cf"))
                    xlist.Add(m.Get("barcode"))
                    xlist.Add(m.Get("parent_id"))
                    mod_gen.db_con.ExecNonQuery2(sql, xlist)
                Next
                mod_gen.db_con.TransactionSuccessful
                mod_gen.db_con.EndTransaction
            End If
        End If
    End If
    job.Release
End Sub
 
Upvote 0

PCastagnetti

Member
Licensed User
Longtime User
try to replace
B4X:
Sub txtBarcode_EnterPressed
    Dim m As EditText = Sender
    search_item(m.Text)
End Sub

with

B4X:
Sub txtBarcode_EnterPressed
    Dim m As EditText = Sender
    CallSubDelayed2(Me,"search_item",m.Text)
End Sub
 
Upvote 0
Top