Android Question Http Error

Azhar

Active Member
Licensed User
Longtime User
Hello All,

All of a sudden (and I have not changed anything, this code below fails to compile. The compiler returns this error:

B4A version: 6.50
Parsing code. (0.09s)
Compiling code. (0.25s)
Compiling layouts code. (0.04s)
Organizing libraries. (0.00s)
Generating R file. (0.09s)
Compiling debugger engine code. (2.96s)
Compiling generated Java code. Error
B4A line: 197
Http.Initialize(\
javac 1.8.0_65
src\b4a\example\geocoderselect.java:626: error: cannot access ClientProtocolException
_http.Initialize("Http");
^
class file for org.apache.http.client.ClientProtocolException not found

Http was initialised in Sub Process_Globals

It has been working fine up until I updated the Android SDK.

Has it anything to do with the Manifest Editor? I changed it to this:

AddManifestText(
<uses-sdk android:minSdkVersion="6" android:targetSdkVersion="23"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
#additionaljar: com.android.support:support-v4
'End of default text.

I'm really stuck as I have no idea why this is creating an error all of a sudden.

Can anyone help?

Kind regards,

Azhar





B4X:
Sub getElevationData()  '(URL As String, taskID As Int)
    Http.Initialize("Http")
    Private HttpRequest1 As HttpRequest
    ALat = Starter.loc.Latiude
    BLat = Starter.loc.Latiude
    ALng = Starter.loc.Longitude
    BLng = Starter.loc.Longitude
    Log("Probing Elevation from URL Request...")
    URL1 = "http://maps.googleapis.com/maps/api/elevation/json?locations="&ALat&","&ALng&"%7C"&BLat&","&BLng
    HttpRequest1.InitializeGet(URL1)
    Http.Execute(HttpRequest1,1)
End Sub

Sub Http_ResponseSuccess (ResponseData As HttpResponse, TaskId As Int)
    my_buffer.InitializeToBytesArray(5000)
    'Do Something with the data that is returned.
    ResponseData.GetAsynchronously("ServerResponse",my_buffer, True, 1)
    Log("In HttpClient1 ResponseSuccess, my_buffer and Data Contained")
End Sub

Sub Http_ResponseError (ResponseData As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
    Log("error: " & ResponseData & " " & StatusCode)
    If ResponseData <> Null Then
        Log(ResponseData.GetString("UTF8"))
        ResponseData.Release
    End If
End Sub

Sub ServerResponse_StreamFinish (Success As Boolean, TaskId As Int)
    Log("In ServerResponse_StreamFinish, Success is " & Success)
    If Success Then
        Private return_buffer () As Byte
        return_buffer = my_buffer.ToBytesArray
        Private returnData As String = BytesToString(return_buffer, 0, return_buffer.Length, "UTF8")
 
        '********************************************
        Log("ALat = "&ALat)
        Log("ALng = "&ALng)
        Log(returnData)
        '********************************************

        'extract elevation from the string
        Dim elevationHeight As String
        Dim a As Int
   
        For a = 1 To return_buffer.Length
            If Common.Mid(returnData,a,9) = "elevation" Then
                'read the string of the elevation value
                elevationHeight = Common.mid(returnData, a + 12, 12)
                Exit
            End If
        Next
        Log("The elevation is " & elevationHeight)
        Starter.loc.Altitude = Common.Val(elevationHeight)
        Log("The loc.alt is " & Starter.loc.Altitude)
    End If
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
Replace your http and httputils2 lib to okhttp and okhttputils2
 
Upvote 0
Top