Android Question JobDone and Job.Release behaviour

FrankBerra

Active Member
Licensed User
Longtime User
Hi all!
Sometimes and on some user's devices I am facing strange crash that i can't understand where they are coming from.
The crashes happens in Jobdone sub and are like this one:
B4X:
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.contains(java.lang.CharSequence)' on a null object reference

After investigating i am wondering if i am using the Job.Release command in the correct way.
For example this is an example how i use Job.Release:
B4X:
Sub JobDone (Job As HttpJob)
  If Job.JobName="Test1" Then
     <...all instructions here...>
     Job.Release
  End if

  If Job.JobName="Test2" Then
     <...all instructions here...>
     Job.Release
  End if
End Sub

I was wondering if the error is due to the fact that i release the job in first IF-THEN and consequently in the second IF-THEN the job is seen as Null...
If it is seen as Null why the exception is rised only on some devices and on some others never happened anything bad for months?

Thanks in advance for your help!
 

Peter Simpson

Expert
Licensed User
Longtime User
You should switch to OkHttpUtils2.

There's nothing wrong with the release, I would just use it once at the bottom of the sub though. Also if your
<...all instructions here...> are short enough, you could always use Select Case instead for ease of reading, but that's just a personal choice.

B4X:
'Something like this
    Select Job.JobName
        Case "Test1"
            <...all instructions here...>
        Case "Test2"
            <...all instructions here...>
    End Select

    Job.Release

Please post more code as you have not really given us enough to go by. I believe that the error mean what you are calling from is actually null, but without more code I personally can't really help you more.
 
Last edited:
Upvote 0

FrankBerra

Active Member
Licensed User
Longtime User
Thanks for answering. Anyway i am using HttpUtils2 version 2.01.
So if there is nothing wrong with Job.Release i think i should investigate more on the null pointer exception... :-/
Is there a way to catch which variable (and not only the sub) is raising the error?
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Try single step debug through the code. Without me quickly putting a test app together I really can't remember, plus I don't have HttpUtils 2 anymore, only OkHttpUtils2 V2.61 which is now recommended.
 
Upvote 0
Top