Android Question android.os.NetworkOnMainThreadException

ibonk64

Member
Licensed User
Longtime User
Hi... My Name Trimanto
i'am a newbie in B4a

I would like to retrieve data from the server and then put it to the database.
but any error message "android.os.NetworkOnMainThreadException"

my code :
B4X:
Sub releasedata
    Dim request1 As HttpRequest 
    Dim respons1 As HttpResponse 
    Dim php,data As String 
   
    conData.Initialize("conData")
    php="501_releasedata.php"
    data="?kdrayon="&kd_rayon
    request1.InitializeGet(url& php & data)
    request1.Timeout = 10000
    If conData.Execute (request1,1)=False Then Return
    Msgbox(url& php & data,"")
    ProgressDialogShow("Sedang Proses data ...")
   
End Sub

Sub conData_responseSuccess (respons1 As HttpResponse , taskid As Int)
    Dim result,data() As String
    result = respons1.GetString("UTF8")
    Dim QDKeterangan,QIKeterangan,Keterangan() As String
    Msgbox(result,"")
    data = Regex.Split("\@",result)
    Msgbox(data,"")
    Dim QIGardu,Gardu(),GarduPecah() As String
   
    Gardu = Regex.Split("\#",data(0))
    For i=0 To Gardu.Length-1
        GarduPecah = Regex.Split("\|",Gardu(i))
        Dim Query As String
        Dim Cursor1 As Cursor
        Query = "SELECT id_gardu FROM gardu WHERE id_gardu = '" & GarduPecah(1) &"' AND kd_rayon= '" & GarduPecah(0) &"'"
        Cursor1 = SQL1.ExecQuery(Query)
        If Cursor1.RowCount = 0 Then
            QIGardu = "INSERT INTO gardu VALUES (?,?,?,?,?,?,?,?,?,?,?,?)"
            SQL1.ExecNonQuery2(QIGardu, Array As String(GarduPecah(0),GarduPecah(1),GarduPecah(2),GarduPecah(3),GarduPecah(4),GarduPecah(5),GarduPecah(6),"","","","",""))
        End If
        Cursor1.Close
    Next
   
   
    QDKeterangan = "DELETE FROM keterangan"
    SQL1.ExecNonQuery(QDKeterangan)
   
    Keterangan = Regex.Split("\|",data(1))
    For i=0 To Keterangan.Length-1
        QIKeterangan = "INSERT INTO keterangan VALUES (?)"
        SQL1.ExecNonQuery2(QIKeterangan, Array As String(Keterangan(i)))
    Next

    Dim QDstatus,QIstatus,status() As String
    QDstatus = "DELETE FROM status"
    SQL1.ExecNonQuery(QDstatus)
   
    status = Regex.Split("\|",data(2))
    For i=0 To status.Length-1
        QIstatus = "INSERT INTO status VALUES (?)"
        SQL1.ExecNonQuery2(QIstatus, Array As String(status(i)))
    Next
   
   
    Dim QDJLampu,QILampu,lampu() As String
    QDJLampu = "DELETE FROM lampu"
    SQL1.ExecNonQuery(QDJLampu)

    lampu = Regex.Split("\|",data(3))
    For i=0 To lampu.Length-1
        QILampu = "INSERT INTO lampu VALUES (?)"
        SQL1.ExecNonQuery2(QILampu, Array As String(lampu(i)))
    Next

    Dim QDdaya,QIdaya,daya() As String
    QDdaya = "DELETE FROM daya"
    SQL1.ExecNonQuery(QDdaya)
   
    daya = Regex.Split("\|",data(4))
    For i=0 To daya.Length-1
        QIdaya = "INSERT INTO daya VALUES (?)"
        SQL1.ExecNonQuery2(QIdaya, Array As String(daya(i)))
    Next

    Dim QDjtiang,QIjtiang,jtiang() As String
    QDjtiang = "DELETE FROM jenis_tiang"
    SQL1.ExecNonQuery(QDjtiang)
   
    jtiang = Regex.Split("\|",data(5))
    For i=0 To jtiang.Length-1
        QIjtiang = "INSERT INTO jenis_tiang VALUES (?)"
        SQL1.ExecNonQuery2(QIjtiang, Array As String(jtiang(i)))
    Next


    Dim QDmilik,QImilik,milik() As String
    QDmilik = "DELETE FROM milik"
    SQL1.ExecNonQuery(QDmilik)
   
    milik = Regex.Split("\|",data(6))
    For i=0 To milik.Length-1
        QImilik = "INSERT INTO milik VALUES (?)"
        SQL1.ExecNonQuery2(QImilik, Array As String(milik(i)))
    Next
   
    Dim QDsambungan,QIsambungan,sambungan() As String
    QDsambungan = "DELETE FROM sambungan"
    SQL1.ExecNonQuery(QDsambungan)
   
    sambungan = Regex.Split("\|",data(7))
    For i=0 To sambungan.Length-1
        QIsambungan = "INSERT INTO sambungan VALUES (?)"
        SQL1.ExecNonQuery2(QIsambungan, Array As String(sambungan(i)))
    Next

    Dim QDWaktu,QIWaktu,waktu() As String
    QDWaktu = "DELETE FROM waktu"
    SQL1.ExecNonQuery(QDWaktu)
   
    waktu = Regex.Split("\|",data(8))
    For i=0 To waktu.Length-1
        QIWaktu = "INSERT INTO waktu VALUES (?)"
        SQL1.ExecNonQuery2(QIWaktu, Array As String(waktu(i)))
    Next

    Dim QDKec,QIKec,kec(),kecPecah() As String
    QDKec = "DELETE FROM kecamatan"
    SQL1.ExecNonQuery(QDKec)

    kec = Regex.Split("\#",data(9))
    For i=0 To kec.Length-1
        kecPecah = Regex.Split("\|",kec(i))
        QIKec = "INSERT INTO kecamatan VALUES (?,?)"
        SQL1.ExecNonQuery2(QIKec, Array As String(kecPecah(0),kecPecah(1)))
    Next
   
   
    Dim QDKel,QIKel,kel(),kelPecah() As String
    QDKel = "DELETE FROM kelurahan"
    SQL1.ExecNonQuery(QDKel)

    kel = Regex.Split("\#",data(10))
    For i=0 To kel.Length-1
        kelPecah = Regex.Split("\|",kel(i))
        QIKel = "INSERT INTO kelurahan VALUES (?,?,?)"
        SQL1.ExecNonQuery2(QIKel, Array As String(kelPecah(0),kelPecah(1),kelPecah(2)))
    Next
   
    ProgressDialogHide
    StartActivity(MainMenu)
End Sub

Sub conData_ResponseError (respons1 As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
    Msgbox("Tidak dapat berkomunikasi dgn server","Warning !")
    Activity.LoadLayout("login")
    ProgressDialogHide
End Sub

any body can help me... thanks before.
 
Top