Android Question Error in HttpUtils2

mw71

Active Member
Licensed User
Longtime User
i use HttpUtils2 whith OKHttp....
In Firebase Crashanalytics i get an error:

Fatal Exception: java.lang.NullPointerException: Attempt to write to field 'boolean de.xxx.xxx.httpjob._success' on a null object reference
at de.xxx.xxx.httputils2service._completejob(httputils2service.java:161)
at de.xxx.xxx.httputils2service._hc_responseerror(httputils2service.java:179)
.....
(if need more from Crashanalytics please ask)

The Code:
B4X:
'HttpUtils2 version 2.10 (based on OkHttp library)
'Service module
Sub Process_Globals
 Private hc As OkHttpClient
 Private TaskIdToJob As Map
 Public TempFolder As String
 Private taskCounter As Int
End Sub

Sub Service_Create
 TempFolder = File.DirInternalCache
 hc.Initialize("hc")
 TaskIdToJob.Initialize
End Sub

Sub Service_Start (StartingIntent As Intent)
End Sub

Sub Service_Destroy
End Sub

Public Sub SubmitJob(job As HttpJob) As Int
 taskCounter = taskCounter + 1
 TaskIdToJob.Put(taskCounter, job)
 If job.Username <> "" And job.Password <> "" Then
  hc.ExecuteCredentials(job.GetRequest, taskCounter, job.Username, job.Password)
 Else
  hc.Execute(job.GetRequest, taskCounter)
 End If
 Return taskCounter
End Sub

Sub hc_ResponseSuccess (Response As OkHttpResponse, TaskId As Int)
 ' ********** Modified Code für DownloadService (from Erel?)*************
 Dim CountStream As CountingOutputStream
 CountStream.Initialize(File.OpenOutput(TempFolder, TaskId, False))
 Response.GetAsynchronously("response", CountStream , True, TaskId)
 '**************************************

'Original
' Response.GetAsynchronously("response", File.OpenOutput(TempFolder, TaskId, False), True, TaskId)
End Sub

Sub Response_StreamFinish (Success As Boolean, TaskId As Int)
 If Success Then
  CompleteJob(TaskId, Success, "")
 Else
  CompleteJob(TaskId, Success, LastException.Message)
 End If
 
End Sub

Sub hc_ResponseError (Response As OkHttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
 If Response <> Null Then
  Starter.cl.lg(Response.ErrorResponse)
  Response.Release
 End If
 CompleteJob(TaskId, False, Reason)
End Sub

Sub CompleteJob(TaskId As Int, success As Boolean, errorMessage As String)
 Dim job As HttpJob = TaskIdToJob.Get(TaskId)
 TaskIdToJob.Remove(TaskId)
 job.success = success
 job.errorMessage = errorMessage
 job.Complete(TaskId)
End Sub
Line 161 -> job.success = success
Line 179 -> CompleteJob(TaskId, False, Reason)

what/where is the Error and what can i do?
 

mw71

Active Member
Licensed User
Longtime User
Note that you are using an old version of OkHttpUtils2.
Never change a running System
I will check to "update"

Are you doing anything special with HttpUtils2Service? Destroying it maybe?
No (i think)
Only the HttpJob Class (V2.01) use it. The HttpJob i use for
- Download (with (GetRequest.SetHeader)
- Download2
- PostBytes/PatchBytes (with GetRequest.SetHeader/SetContentType)
- PostString

For more information (e.g. the Android Version), I have to look later.
 
Upvote 0

mw71

Active Member
Licensed User
Longtime User
I only see once in the Firebase Crashanalytics Console (1 Event/1 User)
- Samsung Device
- Android 9

The latest version is included in the IDE.
For the Next Version I have switch to the "IDE Version"
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…