Android Question OKHTTPUTILS2 Wait For, .GetString Error

james_sgp

Active Member
Licensed User
Longtime User
Hi, Im using OKHTTPUTILS2 with a Wait For; and it is causing me a .GetString error saying 'File Not Found'. I`ve been searching the forum for hours but can`t seem to find a solution. Below is the code I`m using, which I copied from the example:

B4X:
    Dim login_job As HttpJob
    Dim act As String   
    If Connected = True Then
        ProgressDialogShow("Connecting to license server...")
        login_job.Initialize("Login", Me)
        login_job.Download2(strURL & "signin2.php", Array As String("user_id", GetDeviceId, "app", "Mob POS"))
        Wait For (login_job) JobDone(login_job As HttpJob)
        If login_job.Success Then
            Dim parser As JSONParser
            parser.Initialize(login_job.GetString)
            act = parser.NextValue
            Log(act)
 

JohnC

Expert
Licensed User
Longtime User
What is the value for strURL - does it have a "/" at the end of it?
 
Upvote 0

james_sgp

Active Member
Licensed User
Longtime User
Occasionally I get the correct value returned from my PHP script; but more often than not nothing is returned and the app crashes with the 'filenotfound' error although it passed the jobsuccess statement.
Here is the error message:

Error occurred on line: 225 (HttpJob)
java.io.FileNotFoundException: /data/user/0/Mobile.POS/cache/1: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:452)
at java.io.FileInputStream.<init>(FileInputStream.java:76)
at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:214)
at Mobile.POS.httpjob._getstring2(httpjob.java:391)
at Mobile.POS.httpjob._getstring(httpjob.java:79)
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:176)
at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:22)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:250)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
at anywheresoftware.b4a.BA$2.run(BA.java:370)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7331)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
at libcore.io.IoBridge.open(IoBridge.java:438)
... 22 more
 
Last edited:
Upvote 0

james_sgp

Active Member
Licensed User
Longtime User
In case its important, here is the PHP file I`m calling:

B4X:
application/x-httpd-php signin2.php ( PHP script text )
<?php
    require 'db.php';
    try
    {
        if (!isset($_GET['user_id']) || empty($_GET['user_id']) ||
            !isset($_GET['app']) || empty($_GET['app']))
        {
            print json_encode("Parameter Error");
            exit;
        }       
        $uid = $mysqli->escape_string($_GET["user_id"]);
        $app = $mysqli->escape_string($_GET["app"]);

        $sql = "SELECT user_name, reg_status, time_stamp";
        $sql .= " FROM tbl_member";
        $sql .= " WHERE user_id = '".$uid."'";
        $sql .= " AND app_name = '".$app."'";
        $result = $mysqli->query($sql);
        if ($mysqli->errno)
        {
            print json_encode("Error");
            echo "<br />".$mysqli->error;
            exit;
        }
        else
        {
            if ($result->num_rows == 0)
            {
                print json_encode("Not Found");
                exit;
            }
            $row = $result->fetch_row();
            if ($row[1] == "D")
            {
                print json_encode($row[2]);
            }
            else
            {
                print json_encode("Full");

 #               $sql = "UPDATE tbl_member";
 #               $sql .= " SET Online = 'N'";
 #               $sql .= " WHERE now()-time_stamp > 60";           
 #               $mysqli->query($sql);
 #               $sql = "UPDATE tbl_member";
 #               $sql .= " SET logins = logins + 1,";
 #               $sql .= " Online = 'Y',";
 #               $sql .= " time_stamp = now()";
 #               $sql .= " WHERE user_id = '$uid'";
 #               $mysqli->query($sql);
            }
        }
    }
    catch (Exception $e)
    {
        print json_encode("Failed");
        echo '<br />Caught exception: '.$e->getMessage()."\n";
    }   
?>
 
Upvote 0

james_sgp

Active Member
Licensed User
Longtime User
Ok, I think I may have found the problem myself. I as using the AppUdating library, which is sending off an HTTP query to a file on the server; and I`m also talking to an SQL database. I think the problem was the replies where getting mixed up, so I changed my code to make sure AppUpdating has finished first before talking to the SQL Server.
 
Upvote 0

Similar Threads

Top