Android Question Help with OkHttpUtils2!

joaquinortiz

Active Member
Licensed User
Longtime User
Hello!..Thanks in advance for your help!

I'm using the samples that are in this post ,[B4X] OkHttpUtils2 with Wait For, from Erel.

I made a Web Api that it return to me the following value. 255|Ya existe una cuenta con este dominio @xyz.com

B4X:
            Dim j As HttpJob
            j.Initialize("",Me)
            j.Download(lURL)
            wait for (j) jobdone (j As HttpJob)
            ProgressBar.Visible = False
            If j.Success Then
                Log(j.GetString)
                j.Release
                Dim WSResponse As String
                WSResponse = j.getstring

after debugging it shows me an error in line WSResponse = j.getstring

I assume that j.Getstring is a string encoded with UTF8.

What you recommend me to convert into a string value or may be an array.

"255|Ya existe una cuenta con este dominio @xyz.com"
Error occurred on line: 234 (HttpJob)
java.io.FileNotFoundException: /data/user/0/com.basicwms/cache/1 (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:146)
at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:214)
at com.basicwms.httpjob._getstring2(httpjob.java:410)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:22)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
at anywheresoftware.b4a.BA$2.run(BA.java:387)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6165)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
(Exception) java.lang.Exception: java.io.FileNotFoundException: /data/user/0/com.basicwms/cache/1 (No such file or directory)
 

drgottjr

Expert
Licensed User
Longtime User
you can't release j and then go back and read from it.
B4X:
                Log(j.GetString)
                j.Release                                                       ' <<<< YOU CAN'T RELEASE J
                Dim WSResponse As String
                WSResponse = j.getstring                           ' <<<< AND THEN REFER TO IT.  IT'S GONE

do you see this line:
(Exception) java.lang.Exception: java.io.FileNotFoundException: /data/user/0/com.basicwms/cache/1 (No such file or directory) ?
"1" is j. that's the file where the output is saved. until you release it. once you release it, you can't go back to it.

instead, do
Dim WSResponse As String = j.getstring
Log(WSResponse)
j.Release

as for:
What you recommend me to convert into a string value or may be an array.
"255|Ya existe una cuenta con este dominio @xyz.com"

"255|Ya existe una cuenta con este dominio @xyz.com" already is a string. and it's not suitable for an array. what is the problem with it?
 
Upvote 0

joaquinortiz

Active Member
Licensed User
Longtime User
Thanks @drgottjr for helping me.

Log(j.GetString) j.Release ' <<<< YOU CAN'T RELEASE J Dim WSResponse As String WSResponse = j.getstring
You know what?. I just tried it, doing this way and it still show me the same error.

do you see this line:
(Exception) java.lang.Exception: java.io.FileNotFoundException: /data/user/0/com.basicwms/cache/1 (No such file or directory) ?
"1" is j. that's the file where the output is saved. until you release it. once you release it, you can't go back to it.
Wow!, I had no idea about the way OKhttputils2 manage the response.
"255|Ya existe una cuenta con este dominio @xyz.com" already is a string. and it's not suitable for an array. what is the problem with it?
You are rigth!...already it's a string. I'm confusing, why I can do Log(j.Getstring) and see the content of the variable in Logs B4A Window but I can't assign the value to a string variable.

The line where I have breakpoint it crash!.

Just for info, I'm using B4A v10.0

OKHttpUtils2Error1.png
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
you still have j.release before you try to read j. j.release comes after WSResponse = j.getstring. forget log(j.getstring).
do what i told you:
B4X:
Dim WSResponse As String = j.getstring
Log(WSResponse)
j.Release
 
Upvote 0
Top