Android Question --------- beginning of crash

Alam122

Member
B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
/storage/emulated/0/Android/data/b4a.example/files
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Activity (act_login) Create, isFirst = true **
** Activity (act_login) Resume **
** Activity (act_login) Pause, UserClosed = false **
** Activity (act_bio) Create, isFirst = true **
** Activity (act_bio) Resume **
--------- beginning of crash
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.
    Public co1 As SQL
    Public co2 As ResultSet
    
    Dim rp As RuntimePermissions
    Public DBFileName = "data.db" As String
    Public DBFileDir As String
    Public DBTableName  = "siswa" As String
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 txtnama As EditText
    Private txtid As EditText
    Private txtalamat As EditText
    Private txtpt As EditText
    Private txttanggal As EditText
    Private btnsimpan 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("hal_bio")
    co1.Initialize(File.DirDefaultExternal, "data.db", False)
    rp.GetSafeDirDefaultExternal("Connect Sqlite")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub btnsimpan_Click
    'cek data
    If txtnama.Text ="" Then
        Msgbox("Masukkan Nama","info")
        Return
    End If

    If txtid.Text ="" Then
        Msgbox("Masukkan Username","info")
        Return
    End If
    
    If txtalamat.Text ="" Then
        Msgbox("Alamat","info")
        Return
    End If
    
    If txttanggal.Text = "" Then
        Msgbox("Masukkan Tgl-lahir","info")
        Return
    End If
    
    'Cek Data
    co2 = co1.ExecQuery2("SELECT * FROM " & DBTableName & " WHERE nama = ? AND user = ? ", Array As String(txtnama.Text, txtid.Text))
    If co2.NextRow = True Then
        co1.ExecNonQuery("INSERT INTO siswa (alamat, tgllahir, namapt) VALUES('" &txtalamat.Text & "','" & txttanggal.Text & "','" & txtpt.Text & "')")
        Msgbox("Data Berhasil di simpan", "Info")
        Return
        StartActivity(act_akun)
    Else
        co2 = co1.ExecQuery2("SELECT * FROM " & DBTableName & " WHERE nama = ? AND user = ? ", Array As String(txtnama.Text, txtid.Text))
        If co2.NextRow = True Then
            Msgbox("Data Anda salah", "info")
        End If
    End If
End Sub

Sub txttanggal_EnterPressed
    tanggal
End Sub

Sub tanggal
    Dim dd As DateDialog
    Dim x As Int
    
    dd.ShowCalendar=False
    dd.Year = DateTime.GetYear(DateTime.now)
    dd.Month = DateTime.GetMonth(DateTime.now)
    dd.DayOfMonth = DateTime.GetDayOfMonth(DateTime.now)
    x = dd.Show("Masukkan Tanggal : ","", "OK", "Cancel", "", Null)
    If x=DialogResponse.POSITIVE Then
        DateTime.DateFormat="dd-MMM-yyyy"
        txttanggal.Text = DateTime.Date(dd.DateTicks)
    Else
        If x=DialogResponse.CANCEL Then
        txttanggal.Text=""
        End If
    End If
End Sub
 

rosippc64a

Active Member
Licensed User
Longtime User
try debug your program by step-by-step execution! you can learn a lot from that!
write here what happen exactly
 
Upvote 0

advansis

Active Member
Licensed User
Longtime User
I think you should modify your initialization code as:
B4X:
Dim DBPath as string=rp.GetSafeDirDefaultExternal("Connect Sqlite")
co1.Initialize(DBPath, "data.db", False)

I would also use "co1.ExecNonQuery2("INSERT INTO siswa ... VALUES (?,? ...)"
instead of "co1.ExecNonQuery("INSERT INTO siswa..."
 
Upvote 0
Top