"java.lang.RuntimeException: Object should first be initialized." hatası

gacar

Active Member
Merhaba
Veritabanından bir label'e veri yazmak istiyorum. Ancak "java.lang.RuntimeException: Object should first be initialized."
hatası alıyorum.
Bir nesneyi nasıl initialize edebiliriz? Teşekkürler.
Main Sayfasının kodları aşağıda.
B4X:
#Region  Project Attributes 
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName: 
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#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 xui As XUI
    Public SQL As JdbcSQL
#Region Database Location 
    
    Private DBLocation As String = "176.53.62.222" '<====== If I use this not firing and not any error message
    Private DBUsername As String = "UserName"
    Private DBPassword As String = "Pass"
#End Region
    'Private LabelIstanbul As Label
End Sub

Public Sub SQLConnect
    SQL.InitializeAsync("SQL","net.sourceforge.jtds.jdbc.Driver", $"jdbc:jtds:sqlserver://${DBLocation}/TestProject"$, DBUsername, DBPassword)
    Dim rs As JdbcResultSet =  SQL.execquery("select * FROM insaat_demiri where bolge_id=1")
 
    Do While rs.nextrow
        Log(rs.getstring2(1) )
        If LabelIstanbul.IsInitialized Then
            LabelIstanbul.Text = rs.getstring2(1)
        End If     
    Loop
    rs.Close
 
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    Private Button1 As Button
    Private LabelIstanbul As Label 
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")  
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click
    'xui.MsgboxAsync("Hello world!", "B4X")
    SQLConnect
End Sub
 

gacar

Active Member
Erel'in yol göstermesiyle çözümü buldum.

B4X:
Public Sub SQLConnect
    SQL.InitializeAsync("SQL","net.sourceforge.jtds.jdbc.Driver", $"jdbc:jtds:sqlserver://${DBLocation}/TestProject"$, DBUsername, DBPassword)
    
     'Dim rs As JdbcResultSet =  SQL.execquery("select * FROM insaat_demiri where bolge_id=1")
     'Do While rs.nextrow
        'Log(rs.getstring2(1) )
        'If LabelIstanbul.IsInitialized Then
            'LabelIstanbul.Text = rs.getstring2(1)
        'End If     
    'Loop
    'rs.Close
End Sub

Yukarıdaki kod bloğunda yorum satırı haline getirilmiş kısmı aşağıdaki SQL_Ready alt rutinine yerleştirince çalıştı.

B4X:
Sub SQL_Ready (Success As Boolean)
    If Success Then
        Dim rs As JdbcResultSet =  SQL.execquery("select * FROM insaat_demiri")
        Do While rs.nextrow
            LabelIstanbul.Text = rs.getstring2(1)
        Loop
        rs.Close
    Else
        Log(LastException)
        Return
    End If
 
End Sub
 
Top