Android Question Unfortunately App has stopped HTTP Request with no data connection

Derek Jee

Active Member
Licensed User
Longtime User
Hello

I am testing my app to see what happens if I am making an http request and the data connection fails. Simply I turn off the wifi connection and run the process. When I run the request with no wifi I get the Unfortunately app has stopped message. I have put a try/end try around the code to see where it errors but it does not trap it. I am running in release mode too when I turn off my wifi. Of course I am checking for a connection before I run this process but I want to make sure the app doesn't crash if connection fails after the check..

Can anyone advise?

Many thanks,


Derek.
 
are you placing the try/end try around the download .init and .download or in the jobdone sub?
 
Upvote 0
I have it round the post/put request code and the jobdone..
 
Upvote 0
Code:
    Try
   
    'Log("JobName = " & Job.JobName & ", Success = " & Job.Tag & ", Error = " & Job.ErrorMessage & ", Response Body = " & Job.GetString)
    Dim x As String = Job.Tag
   
    Select x
   
        Case 200

            Dim Headers As Map= Job.HTag
            Dim y As String = Headers.Get("Authorization")

            SQL1.ExecNonQuery("UPDATE Parameters Set strUserCredentials = '" & HashedCredentials & "', strToken = '" & y & "', strUserID = '" & txtUsername.Text & "' WHERE id = 1")
            Job.Release
            StartActivity("HomePage")
               
        Case 401
            pnlInfo.Visible = True
            lblInfo.Text = "Incorrect Username Or Password Entered"
           
        Case 403
            pnlInfo.Visible = True
            lblInfo.Text = "User Is Unauthorised.  Please Contact Your Administrator"
       
    End Select
   
       Job.Release
   
    Catch
   
        Log("No Connection")
        ToastMessageShow("Try Local Logon", True)
   
    End Try
 
Upvote 0
I have a series of toast messages and it does not get to the jobdone sub. It runs the request code ok. I guess it is the httputils2 or httpjob which is unhappy?

(Sorry, yes I have a check too for Jobsucess)
 
Upvote 0
try this and see what happends

Code:
Sub Process_Globals
End Sub

Sub Globals
Dim dljob As HttpJob
End Sub

Sub Activity_Create(FirstTime As Boolean)
dljob.Initialize("test",Me)
dljob.Download("http://www.google.com")
End Sub

Sub JobDone(job As HttpJob)
Log("job done")
   If job.Success Then
       Log(job.GetString)
   Else
     Log("Error: " & job.ErrorMessage)
   End If
   job.Release
End Sub


when I turn Wifi off I get (without a crash)

Code:
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
job done
Error: java.net.UnknownHostException: www.google.com
 
Upvote 0
Hi Sorex

I get the same error but no logs as I am not connected to the wifi..
 
Upvote 0
that's strange, it should always write something to the log if the download executes.

is that on a real device or some emulator?
 
Upvote 0
Sub Globals
Dim dljob As HttpJob
End Sub

Sub Activity_Create(FirstTime As Boolean)
dljob.Initialize(
"test",Me)
dljob.Download(
"http://www.google.com")
End Sub

Not a good idea to use the job in globals! You should DIM a NEW httpjob each time!
Code:
Sub Globals
'Dim dljob As HttpJob
End Sub

Sub Activity_Create(FirstTime As Boolean)
Dim dljob As HttpJob
dljob.Initialize("test",Me)
dljob.Download("http://www.google.com")
End Sub
 
Upvote 0
Hi Sorex

It is a device.. Would it log anything if it had no connection?
 
Upvote 0
But if I have no wifi how can it log the job done? I have done this in release and legacy mode with the same problem.. I am worried that my app will just die and I can't trap the error. I will have to look at the HTTPutils2 to see if that is what is erroring..
 
Upvote 0
yes, the job should always complete but it will be unsuccessfull (job.success = false)
 
Upvote 0
I though it did.. So if I send a request with no data connection at all it should still fire the jobdone sub but with success = false?

I am using HTTPUtils2 v2.01..
 
Upvote 0
Well... I think I have found the issue..

When I first installed the HTTPUtils2 I needed to receive the statuscode of an unsuccessful request so was advised to put in the following code to the hc_errorresponse sub.. Of course this errors when there is no connection because there is no tag.... I have trapped that code and it seems to have done the trick..

I must say a big thank you to you and sorry to have wasted your time. Thank you..

Code:
    Dim job As HttpJob = TaskIdToJob.Get(TaskId)
    job.Tag = Response.StatusCode
 
Upvote 0
Back
Top