Android Question java.lang.RuntimeException: Object should first be initialized.

Alam122

Member
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 xui As XUI
    
    Public ko As SQL
    
    
    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, txtuser, txtpass, txtno As B4XView
    
    Dim B64 As Base64
    Dim epass As String

    Private Button1 As B4XView
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_daftar")
End Sub

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

    If txtuser.Text ="" Then
        Msgbox("Masukkan Username","info")
        Return
    End If
    
    If txtpass.Text ="" Then
        Msgbox("Password","info")
        Return
    End If
    
    If txtno.Text ="" Then
        Msgbox("Masukkan No.Handphone","info")
        Return
    End If
    
    'checks if the data already exist in the database
    Public co As ResultSet
    co = ko.ExecQuery2("SELECT * FROM " & DBTableName & " WHERE nama = ? AND user = ? AND password = ? AND notelepon = ?", Array As String(txtnama.Text, txtuser.Text, txtpass.Text, txtno.Text))
    If co.NextRow = True Then
        'if yes display a MessageBox
        xui.MsgboxAsync("Username dan Password sudah digunakan","info")
        Else
        Private mapRow As Map
        
    'defines the Map with the column names as key and the values
    mapRow.Initialize
    mapRow.Put("Nama Lengkap", txtnama.Text)
    mapRow.Put("Username", txtuser.Text)
    mapRow.Put("Password", txtpass.Text)
    mapRow.Put("No.Telepon", txtno.Text)
        
    'memanggil enkripsi
    encript
    
    Activity.Finish
    StartActivity(act_login)
    End If
End Sub

Sub encript
    epass = B64.EncodeStoS(txtpass.Text, "UTF8")
End Sub
 

Alam122

Member
please help me, i got problem with add data to database
Screenshot (32).png
 
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
somewhere (i.e. in the Activity_Create()) you need to write:

ko.Initialize(DBFilePath, DBFileName, createifnotexists)

you need to set db path name also, create db, create tables, etc.
 
Upvote 0

Alam122

Member
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.

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.

    Dim B64 As Base64
    Dim epass As String

    Private txtnama As EditText
    Private txtuser As EditText
    Private txtpass As EditText
    Private txtno As EditText
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_daftar")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


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

    If txtuser.Text ="" Then
        Msgbox("Masukkan Username","info")
        Return
    End If
    
    If txtpass.Text ="" Then
        Msgbox("Password","info")
        Return
    End If
    
    If txtno.Text ="" Then
        Msgbox("Masukkan No.Handphone","info")
        Return
    End If
    
    mdl_koneksi.koneksi

    'validasi
    mdl_koneksi.co2 = mdl_koneksi.co1.Query("SELECT * FROM data WHERE user ='" & txtuser.Text & "'")
    If mdl_koneksi.co2.RowCount > 0 Then
        Msgbox("Username sudah digunakan", "info")
        txtuser.Text= ""
        Return
        mdl_koneksi.co1.Close
    Else
        'simpan data
        mdl_koneksi.co1.Exec("INSERT INTO data (user, nama, password, notelepon) VALUES('" & txtnama.Text & "','" & txtuser.Text & "','" & epass  & "','" & txtno.Text  & "')")
    
    mdl_koneksi.co1.Close
    
        'encrypt
        encrypt
        
        Activity.Finish
        StartActivity(act_login)
    End If
End Sub

Sub encrypt
    epass = B64.EncodeStoS(txtpass.Text, "UTF8")
    End Sub
 
Upvote 0

Alam122

Member
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Activity (act_login) Create, isFirst = true **
** Activity (act_login) Resume **
** Activity (act_login) Pause, UserClosed = true **
** Activity (act_daftar) Create, isFirst = true **
** Activity (act_daftar) Resume **
Error occurred on line: 82 (act_daftar)
java.lang.RuntimeException: Object should first be initialized (ResultSet).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at mysql.mysqlhandler$ResultSetWrapper.RowCount(mysqlhandler.java:194)
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:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:6597)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25885)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

B4X:
 
Upvote 0

Alam122

Member
somewhere (i.e. in the Activity_Create()) you need to write:

ko.Initialize(DBFilePath, DBFileName, createifnotexists)

you need to set db path name also, create db, create tables, etc.

I had declare datafield and dbfilename but why the error "object should be first initialized" ?
 
Upvote 0
Top