How to verify server response?

0

I am developing an android app, the server responds to me by creating a json from php, but now it takes time to generate the text and until then the AsycnAsk already receives me as a null error.

How can I do to control that?

This is the function.

private class ProductosLoadTask extends AsyncTask<Void, Void, Cursor> {
    @Override
    protected Cursor doInBackground(Void... voids) {
        try{
            mDbHelper.BorrarProductos();             
            JsonArrayRequest jsonArrayReq = new JsonArrayRequest(url_productos,
                    new Response.Listener<JSONArray>() {
                        @Override
                        public void onResponse(JSONArray response) {                             
                            try
                            {
                                txt_tot_pro.setText("Espere... procesando");
                                JSONObject obj=null;                                                                        
                                for (int a=0; a<response.length();a++) {                                        
                                    obj = response.getJSONObject(a);                                      
                                    save_producto=new producto(
                                            obj.getString("IMA_ARTICULO"),
                                            obj.getString("IMA_DESCRIPCION"),
                                            obj.getString("IMA_LINEA"),
                                            obj.getString("IMA_IMPUESTO"),
                                            obj.getString("IMA_COSTO_PROMEDIO"),
                                            obj.getString("IMA_PRECIO1"),
                                            obj.getString("IMA_PRECIO2"),
                                            obj.getString("IMA_PRECIO3"),
                                            obj.getString("IMA_PRECIO4"),
                                            obj.getString("IMA_PRECIO5"),
                                            obj.getString("IMA_PRECIO6"),
                                            obj.getString("IMA_PRECIO7"),
                                            obj.getString("IMA_PRECIO8"),
                                            obj.getString("IMA_PRECIO9"),
                                            obj.getString("IMA_PRECIO10"),
                                            obj.getString("IMA_SUBLINEA"),
                                            obj.getString("EXISTENCIA"),
                                            obj.getString("PACK"),"1","cb");
                                    mDbHelper.nuevoProducto(save_producto);
                                }
                                txt_tot_pro.setText("Listo, sincronizacion completa");
                                SyncReceive(posSyncRe);
                            }catch (JSONException e){
                                Log.e(TAG, "parseJsonProductos ",e );
                            }
                        }
                    }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                    VolleyLog.d(TAG, "ErrorProductos: " + error.getMessage());
                    Log.i(TAG, "onErrorResponseProductos: "+error.getMessage());
                }
            });
            Volley.newRequestQueue(getActivity()).add(jsonArrayReq);
        }catch (Exception error){
            Log.i(TAG, "parseJsonProductos error: " + error.toString());
        }
        return null;
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        txt_tot_pro.setText("Espere... Conectando");
    }

    @Override
    protected void onPostExecute(Cursor cursor) {
        super.onPostExecute(cursor);
        txt_tot_pro.setText("Sincronizado(s)  producto(s)");
    }
}
    
asked by Alldesign Web 29.09.2017 в 17:09
source

0 answers