Android Question Error Java Lang stackoverflow

Infotech

Member
Licensed User
When i back activity or input activity, my apps so frezee and then force close
B4X:
#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.
    Private ServerUrl As String = "http://192.168.1.13/Test1/Default.aspx"
    Dim s As SQL
    Dim kode As String
    Dim stringutils1,stringutils2 As StringUtils
    Dim FTP As FTP
    Dim list1,list2 As List
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.

    Dim gg As Int
    Dim l As Label
    Dim c,cc As Cursor
    Dim SV As ScrollView
    Dim Header As Panel
    Dim Table As Panel
    Dim NumberOfColumns, RowHeight, ColumnWidth As Int
    Dim HeaderColor, TableColor, FontColor, HeaderFontColor As Int
    Dim FontSize As Float
    Type RowCol3 (Row As Int, col As Int)
    Dim Alignment As Int
    Dim SelectedRow As Int
    Dim SelectedRowColor As Int
    Dim rows As List
    Dim str As String
    Dim btnadd As Button
    Dim btnedit As Button
    Dim btndelete As Button
   

    'Table settings
    HeaderColor = Colors.Gray
    NumberOfColumns = 8
    RowHeight = 50dip
    TableColor = Colors.White
    FontColor = Colors.Black
    HeaderFontColor = Colors.White
    FontSize = 16
    Alignment = Gravity.CENTER_HORIZONTAL'change to Gravity.LEFT or Gravity.RIGHT for other alignments.
    SelectedRowColor = Colors.Blue
    Private edtdiskon As EditText
    Private spinlokasi As Spinner
    Private spincustomer As Spinner
    Private lbltanggal As Label
    Private lbnofaktur As Label
    Private edtsubtotal As EditText
    Private edttotal As EditText
    Private btntransaksi As Button
    Private Button1 As Button
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("Awal")
       
    Activity.Title = "Tansaksi Penjualan"

    Dim Ruta As String
   
    If File.ExternalWritable Then
        Ruta = File.DirDefaultExternal
    Else
        Ruta = File.DirInternal
    End If
   
    If File.Exists(Ruta, "Transaksi.db") = False Then
        File.Copy(File.DirAssets, "Transaksi.db", Ruta, "Transaksi.db")
    End If
   
    s.Initialize(Ruta, "Transaksi.db", True)
   
    lbltanggal.Text = DateUtils.TicksToString(DateTime.Now)
    gg=0
   
    For i=0 To 5
        spincustomer.Add("cus"&(i))
    Next
   
    loadlokaCSV(File.DirRootExternal, "PSLOKA.csv", True)
    loadCosCSV(File.DirRootExternal, "PJSALS.csv", True)
   
    If FirstTime Then
        FTP.Initialize("FTP", "192.168.1.15", 21, "infotech", "infotech123")
    End If
   
   
End Sub

Sub Activity_Resume
    SV.Initialize(0)
    SV.Color = Colors.White
    btnadd.Initialize("button_add")
    btnedit.Initialize("button_edit")
    btndelete.Initialize("button_dlt")
    Table = SV.Panel
    Table.Color = TableColor
    Activity.AddView(SV, 0%x, 24%y, 101%x, 45%y)
    Activity.AddView(btnadd, 3%x, 80%y, 20%x, 5%y)
    Activity.AddView(btnedit, 25%x, 80%y, 20%x, 5%y)
    Activity.AddView(btndelete, 15%x, 85%y, 20%x, 5%y)
    btnadd.Text = "Add Item"
    btnedit.Text = "Edit"
    btndelete.Text = "Delete"
    btndelete.Enabled = False
    btnedit.Enabled = False
    ColumnWidth = SV.Width / NumberOfColumns
    SelectedRow = -1
   
    tampil
   
    Dim cs As Cursor
    cs = s.ExecQuery("Select SUM(NilaiRP) AS SUBTOTAL FROM PJTabelBayangan")
       
    If cs.RowCount>0 Then
           
            cs.Position = 0
            edtsubtotal.Text = cs.GetString("SUBTOTAL")
   
    End If

    If edtsubtotal.Text = "null" Then
        btntransaksi.Enabled = False
        edtsubtotal.Text = "0"
    Else
        btntransaksi.Enabled = True
        Hitung
    End If
   
    Dim cu As Cursor
    cu = s.ExecQuery("SELECT NOFAKTUR FROM PJHEAD ORDER BY NOFAKTUR DESC")
       
    If cu.RowCount> 0 Then
       
        For i=0 To cu.RowCount-1
            cu.Position = 0
            lbnofaktur.Text = cu.GetString("NOFAKTUR")
        Next
    End If
End Sub


Sub Cell_Click
    Dim rc As RowCol
    Dim l As Label
    l = Sender
    rc = l.Tag
    SelectRow(rc.Row)
    c.Position = rc.Row
    EditData.id = c.GetString("No")
    kode = c.GetString("Kode_stock")
    btnedit.Enabled = True
    btndelete.Enabled = True
End Sub

Sub SelectRow(Row As Int)
    'remove the color of previously selected row
    If SelectedRow > -1 Then
        For col = 0 To NumberOfColumns - 1
            GetView(SelectedRow, col).Color = Colors.Transparent
        Next
    End If
    SelectedRow = Row
    For col = 0 To NumberOfColumns - 1
        GetView(Row, col).Color = SelectedRowColor
    Next
End Sub
Sub GetView(Row As Int, Col As Int) As Label
    Dim l As Label
    l = Table.GetView(Row * NumberOfColumns + Col)
    Return l
End Sub
Sub AddRow(Values() As String)
    If Values.Length <> NumberOfColumns Then
        Log("Wrong number of values.")
        Return
    End If
    Dim lastRow As Int
    lastRow = NumberOfRows
    For i = 0 To NumberOfColumns - 1
        l.Initialize("cell")
        l.Text = Values(i)
        l.Gravity = Alignment
        l.TextSize = FontSize
        l.TextColor = FontColor
       
        Dim rc As RowCol
        rc.Initialize
        rc.Col = i
        rc.Row = lastRow
        l.Tag = rc
        Table.AddView(l, ColumnWidth * i-5, RowHeight * lastRow, ColumnWidth, RowHeight)
    Next
    Table.Height = NumberOfRows * RowHeight
End Sub
Sub SetHeader(Values() As String)
    If Header.IsInitialized Then Return 'should only be called once
    Header.Initialize("")
    For i = 0 To NumberOfColumns - 1
        Dim l As Label
        l.Initialize("header")
        l.Text = Values(i)
        l.Gravity = Gravity.CENTER_HORIZONTAL
        l.TextSize = FontSize
        l.Color = HeaderColor
        l.TextColor = HeaderFontColor
        l.Tag = i
        Header.AddView(l, ColumnWidth * i, 0, ColumnWidth, RowHeight)
    Next
    Activity.AddView(Header, SV.Left, SV.Top - RowHeight, SV.Width, RowHeight)
End Sub
Sub NumberOfRows As Int
    Return Table.NumberOfViews / NumberOfColumns
End Sub

Sub SetCell(Row As Int, Col As Int, Value As String)
    GetView(Row, Col).Text = Value
End Sub
Sub GetCell(Row As Int, Col As Int) As String
    Return GetView(Row, Col).Text
End Sub
Sub ClearAll
    For i = Table.NumberOfViews -1 To 0 Step -1
        Table.RemoveViewAt(i)
    Next
    Table.Height = 0
    SelectedRow = -1
End Sub


Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub button_add_Click
    StartActivity(InputData)

End Sub

Sub spinlokasi_ItemClick (Position As Int, Value As Object)

End Sub

Sub spincustomer_ItemClick (Position As Int, Value As Object)
   
End Sub

Sub edtdiskon_FocusChanged (HasFocus As Boolean)
    If (HasFocus = False And edtdiskon.Text = "") Or edtdiskon.Text = 0 Then
        edtdiskon.Text = "0"
    End If
   

    edtdiskon.SelectionStart = edtdiskon.Text.Length
End Sub

Sub Hitung
    If edtdiskon.Text = "" Then
       
    Else
        Dim diskon, subharga, totalharga As Double
   
        diskon = edtdiskon.Text
        subharga = edtsubtotal.Text
        totalharga = edttotal.Text
   
        totalharga = subharga - (diskon/100)
   
        edttotal.Text = totalharga
   
    End If
End Sub

Sub edtdiskon_TextChanged (Old As String, New As String)
    Dim sst As String

    sst = edtdiskon.Text
    sst = NumberFormat(sst,0,2)
   
    edtdiskon.Text = sst
    Hitung
End Sub


Sub btntransaksi_Click
    cc = s.ExecQuery("SELECT * FROM online")
    cc.Position=0
   
    str = cc.GetString("tipe")
   
    UpdateInsertPJHead
    InsertPJTRns
    Activity.Finish
    StartActivity(Me)
   
    s.ExecNonQuery("DELETE FROM PJTabelBayangan")
End Sub

Sub button_edit_Click
   
    StartActivity(EditData)
    EditData.Edit = "Ya"
End Sub

Sub button_dlt_Click
    Dim result As Int
    result = Msgbox2("Hapus data yangb terpilih?", "Peringantan", "Ya", "", "Tidak", Null)
    If result = DialogResponse.Positive Then
        s.ExecNonQuery("DELETE FROM PJTabelBayangan Where Kode_stock = '"&kode&"'")
        ClearAll
        ToastMessageShow("Data Telah di Hapus",False)
        StartActivity(Me)
    End If
End Sub

Sub UpdateInsertPJHead
   
    If str = "online" Then
    s.ExecNonQuery("UPDATE PJHead SET Tanggal = '"&DateUtils.TicksToString(DateTime.Now)&"', Kode = '"&spincustomer.SelectedItem&"', Lokasi = '"&spinlokasi.SelectedItem&"', Bruto = '"&edtsubtotal.Text&"', Diskon = '"&edtdiskon.Text&"', Netto = '"&edttotal.Text&"', kondisi = '1' WHERE NOFAKTUR = '"&lbnofaktur.Text&"'")
        Log("MASUK SINiI"&str)
        Dim row(7) As String
       
        row(0) = DateUtils.TicksToString(DateTime.Now)
        row(1) = spincustomer.SelectedItem
        row(2) = spinlokasi.SelectedItem
        row(3) = edtsubtotal.Text
        row(4) = edtdiskon.Text
        row(5) = edttotal.Text
        row(6) = lbnofaktur.Text
    list2.Initialize
    list2.Add(row)
    stringutils2.SaveCSV(File.DirRootExternal,"PJHEAD.csv",";",list2)
    FTP.UploadFile(File.DirRootExternal, "PJHEAD.csv", True, "/Datader/PJHEAD("&lbnofaktur.Text&").csv")
    Else
    s.ExecNonQuery("UPDATE PJHead SET Tanggal = '"&DateUtils.TicksToString(DateTime.Now)&"', Kode = '"&spincustomer.SelectedItem&"', Lokasi = '"&spinlokasi.SelectedItem&"', Bruto = '"&edtsubtotal.Text&"', Diskon = '"&edtdiskon.Text&"', Netto = '"&edttotal.Text&"', kondisi = '0' WHERE NOFAKTUR = '"&lbnofaktur.Text&"'")
    Log("MASUK SINI"&str)
    End If
    s.ExecNonQuery("INSERT INTO PJHead (Bruto) Values('0')")
End Sub

Sub InsertPJTRns
    If str = "online" Then
    For i=0 To c.RowCount-1
        c.Position=i
        s.ExecNonQuery("INSERT INTO PJTrans (NOFAKTUR, Kode_Stock, QTY, Unit, Harga, Diskon, NilaiRp, kondisi) VALUES ('"&lbnofaktur.Text&"', '"&c.GetString("Kode_stock")&"', '"&c.GetString("QTY")&"', '"&c.GetString("Unit")&"', '"&c.GetString("Harga")&"', '"&c.GetString("Diskon")&"', '"&c.GetString("NilaiRp")&"','1')")
    Next
    SaveTableToCSV(File.DirRootExternal, "PJTRANS.csv")
    FTP.UploadFile(File.DirRootExternal, "PJTRANS.csv", True, "/Datader/PJTRANS("&lbnofaktur.Text&").csv")
    Else
    For i=0 To c.RowCount-1
            c.Position=i
            s.ExecNonQuery("INSERT INTO PJTrans (NOFAKTUR, Kode_Stock, QTY, Unit, Harga, Diskon, NilaiRp, kondisi) VALUES ('"&lbnofaktur.Text&"', '"&c.GetString("Kode_stock")&"', '"&c.GetString("QTY")&"', '"&c.GetString("Unit")&"', '"&c.GetString("Harga")&"', '"&c.GetString("Diskon")&"', '"&c.GetString("NilaiRp")&"','0')")
    Next
    End If
End Sub


Sub loadlokaCSV(Dir As String, Filename As String, HeadersExist As Boolean)
    spinlokasi.Clear
    list1 = stringutils1.LoadCSV(Dir, Filename, ";")
    For i = 0 To list1.Size - 1
        Dim row() As String
        row = list1.Get(i)
        spinlokasi.Add(row(0))
    Next
End Sub

Sub loadCosCSV(Dir As String, Filename As String, HeadersExist As Boolean)
    spincustomer.Clear
    list1 = stringutils1.LoadCSV(Dir, Filename, ";")
    For i = 0 To list1.Size - 1
        Dim row() As String
        row = list1.Get(i)
        spincustomer.Add(row(2))
    Next
End Sub



Sub SaveTableToCSV(Dir As String, Filename As String)
    Dim headers(NumberOfColumns) As String
    For i = 0 To headers.Length - 1
        Dim l As Label
        l = Header.GetView(i)
        headers(i) = l.Text
    Next
    Dim list1 As List
    list1.Initialize
    For i = 0 To NumberOfRows - 1
        Dim row(NumberOfColumns) As String
        For j = 0 To NumberOfColumns - 1
            If j=0 Then
                row(j) = lbnofaktur.Text   
            Else
                row(j) = GetCell(i, j)
            End If
           
        Next
        list1.Add(row)
    Next
    stringutils1.SaveCSV2(Dir, Filename, ";", list1, headers)
End Sub

Sub FTP_UploadProgress (ServerPath As String, TotalUploaded As Long, Total As Long)
    Dim w As String
    w = "Uploaded " & Round(TotalUploaded / 1000) & "KB"
    If Total > 0 Then w = w & " out of " & Round(Total / 1000) & "KB"
    Log(w)
End Sub

Sub FTP_UploadCompleted (ServerPath As String, Success As Boolean)
    Log(ServerPath & ", Success=" & Success)
    If Success = False Then Log(LastException.Message)
End Sub

Sub tampil
   
    SetHeader(Array As String("No","Kode Stock", "Nama Brg","qty","unit","Harga","Disc","Nilai RP"))
   
    c = s.ExecQuery("SELECT * FROM PJTabelBayangan")

    ClearAll
   
    Dim colum1(c.RowCount) As String
    Dim colum2(c.RowCount) As String
    Dim colum3(c.RowCount) As String
    Dim colum4(c.RowCount) As String
    Dim colum5(c.RowCount) As String
    Dim colum6(c.RowCount) As String
    Dim colum7(c.RowCount) As String
    Dim colum8(c.RowCount) As String
    If c.RowCount> 0 Then
       
        For i=0 To c.RowCount-1
            c.Position=i
            colum1(i) = c.GetString("No")
            colum2(i) = c.GetString("Kode_stock")
            colum3(i) = c.GetString("NamaBrg")
            colum4(i) = c.GetString("QTY")
            colum5(i) = c.GetString("Unit")
            colum6(i) = c.GetString("Harga")
            colum7(i) = c.GetString("Diskon")
            colum8(i) = c.GetString("NilaiRp")
        Next
    End If
    For i = 0 To c.RowCount-1
        AddRow(Array As String(i+1, colum2(i), colum3(i), colum4(i), colum5(i), colum6(i), colum7(i), colum8(i)))
    Next
   
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
1. Export your project as ZIP and upload this zip.
2. Post the error from the LOG if your app freezes. We can not help if we do not know the problem.
3. You should load the layout (add the Objects it to the activity) in Activity_Create. NOT in Resume.
 
Upvote 0
Top