Android Question Unable to resolve host using OkHttpUtils2

Discussion in 'Android Questions' started by DawningTruth, Jun 22, 2019.

Tags:
  1. DawningTruth

    DawningTruth Active Member Licensed User

    I am using the following boilerplate code for OkHttpUtils2 with Wait For:
    Code:
    Public Sub FetchData

       
    Dim myJob As HttpJob
     
       myJob.Initialize(
    "", Me)
       myJob.Download(
    "https://www.wikipedia.org/")
       
    Wait For (myJob) JobDone (myJob As HttpJob)
       
    If myJob.Success Then
           
    Log(myJob.GetString)
       
    Else
           
    Log("Error: " & myJob.ErrorMessage)
       
    End If
       myJob.Release
         
    End Sub
    The only thing out of the ordinary is this Sub is run from a separate class.

    I was getting an error with my website, so I tried a couple of others. I keep getting the following error in the logs:

    *** Service (httputils2service) Create ***
    ** Service (httputils2service) Start **
    ResponseError. Reason: java.net.UnknownHostException: Unable to resolve host "www.wikipedia.org": No address associated with hostname, Response:
    Object context is paused. Ignoring CallSubDelayed: JobDone

    On other occasions I just get:

    *** Service (httputils2service) Create ***
    ** Service (httputils2service) Start **
    Object context is paused. Ignoring CallSubDelayed: JobDone


    Everything should be working. Any suggestions?
     
    Last edited: Jun 22, 2019
  2. mare1980k1

    mare1980k1 Member Licensed User

    Try to put Public Sub FetchData in starter activity. It seems that activity that you are initializing it right now from gets paused, so it causes errors.
    Also try to add this in manifest
    Code:
    AddPermission(android.permission.INTERNET)
     
    Last edited: Jun 22, 2019
    DawningTruth likes this.
  3. Erel

    Erel Administrator Staff Member Licensed User

    The permission will be added automatically.

    This error happens when you omit the http(s) scheme from the URL.

    This happens when the parent activity is paused. Move the code to a class that is initialized from the starter service.
     
    mare1980k1 and DawningTruth like this.
  4. DawningTruth

    DawningTruth Active Member Licensed User

    Thx for all the help :).

    Managed to get it working. Had to break my architectural separation. Basically I moved the Sub from the separate data fetching class to the active Activity and it worked without any code changes.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice