Android Question android > 4.0 NetworkOnMainThreadException error help

Spinter

Active Member
Licensed User
I'm using HttpRequest to communicate with my mysql but with a device SDK 2.2 everything works perfectly! device with a 4.0 sdk I go to NetworkOnMainThreadException.
How do I get out?

1.png
 
Last edited by a moderator:

B4A Enthusiast

Member
Licensed User
Hi, am facing an interesting situation; when i run my app in debug(rapid) mode it runs okay.
When i run in Release mode, it brings an error when I press the Login button. The error is:

"An error occured in sub: android.os.NetworkOnMainThreadException"

The entire Login Button Click Event Code is as follows:

B4X:
Dim rows As Int,strPass As String
    Dim a As MSSQL, L As List

    a.setDatabase("192.168.1.2","DBNAME","username","pswd")

    strPass = ModuleEncrypt.RC4(txtPassword.Text, "PUBLIC_KEY")

    L=a.Query("select * from Passwords Where UserName = '" & txtUserName.Text & "' And Password = '" & strPass & "'")

    If L.IsInitialized=False Then
        Msgbox("YOUR CREDENTIALS FAILED TO AUTHENTICATE","PLEASE TRY AGAIN!")
    Else
        If L.Size>0 Then
  
            rows = L.Size
      
            If rows=1 Then
                Msgbox("YOUR CREDENTIALS FAILED TO AUTHENTICATE","PLEASE TRY AGAIN!")
            Else
                IME1.HideKeyboard
                Activity.RemoveAllViews
                MyPhone.SetScreenOrientation(-1)'Release Orientation
                Activity.LoadLayout("SectionChoice")
                FormatSectionChoiceViews
                DoEvents
            End If
        Else
            Msgbox("Sorry, Authentication Failed." & CRLF & "Please Try Again","INVALID USER DETAILS")
        End If
    End If

Please help me out - have scratched my head enough times!
Thanks.
 
Last edited:
Upvote 0

B4A Enthusiast

Member
Licensed User
Okay Erel. Well put.

I followed your advise and decided to go the RDC way. Am however unable to setup the RDC Server Successfully.
Am getting the attached error.


RDC Error.png



What is it that am not doing correctly? Thanks.
 
Upvote 0

B4A Enthusiast

Member
Licensed User
Sure, here is my config file

Config File.png


However inside the jdbc_driver folder there is a conf folder in which I changed the settings as follows:


connection_properties_tmpl.png



Advise Erel...

 
Upvote 0
Top