使用volly,Json Object从MySQL获取数据时的Java EOF异常

时间:2017-01-10 10:24:26

标签: php android mysql json android-volley

我不知道发生了什么..我的应用程序工作正常,但现在我收到了这个错误..我没有改变任何代码。

我试图从Volly获取数据但获得Java Eofexception ..这是我的功能

private void getData() {

    db = new SQLiteHandler(getApplicationContext());
    // Fetching user details from sqlite
    HashMap<String, String> user = db.getUserDetails();
    String uid = ConfirmActivity.Img_path;


    loading = ProgressDialog.show(this,"Almost done","now Fetching your result...",false,false);

    String url = AppConfig.DATA_URL+uid;

    StringRequest stringRequest = new StringRequest(url, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            loading.dismiss();
            showJSON(response);
        }
    },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Toast.makeText(getApplication(),error.getMessage().toString(), Toast.LENGTH_LONG).show();
                }
            });

    RequestQueue requestQueue = Volley.newRequestQueue(this);
    requestQueue.add(stringRequest);
}

private void showJSON(String response){
    String disease="";
    String date_time;
    try {
        JSONObject jsonObject = new JSONObject(response);
        JSONArray result = jsonObject.getJSONArray(JSON_ARRAY);
        JSONObject collegeData = result.getJSONObject(0);
        disease = collegeData.getString(KEY_DISEASE);
        date_time = collegeData.getString(KEY_DATETIME);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    Toast.makeText(getApplicationContext(),
            disease, Toast.LENGTH_LONG)
            .show();
    Disease_name = (TextView)findViewById(R.id.textView_dname);
    diseases = disease;
    Disease_name.setText(disease);

}

这是我的php端代码:

<?php 

if($_SERVER['REQUEST_METHOD']=='GET'){

    $uid  = $_GET['uid'];

    require_once 'include/DB_Conn.php';

    $sql = "SELECT result,date_time FROM detected_disease WHERE image_path='".$uid."' and status IS NULL ORDER BY dd_id DESC limit 1";
    $sql2 = "UPDATE detected_disease SET status = 1 WHERE image_path='".$uid."' ORDER BY dd_id DESC limit 1";

    $r = mysqli_query($conn,$sql);

    $res = mysqli_fetch_array($r);

    $result = array();

    array_push($result,array(
        "result"=>$res['result'],
        "date_time"=>$res['date_time']
        )
    );

    echo json_encode(array("result"=>$result));
    $r = mysqli_query($conn,$sql2);

    mysqli_close($conn);

}   

Android监视器中没有错误,并且不知道这个错误是如何发生的.. 我搜索过类似的错误,但我没有发现任何线索。 我还检查了我的应用程序发送到api的值...这没关系..

其次..这个php代码在浏览器中工作正常..给出了预期的结果。

请帮助.. THX

0 个答案:

没有答案