Mori Ruec Mori Ruec - 3 months ago 16
Apache Configuration Question

Getting Android Volley null error after calling specific php functions, other functions work fine

I've got an android application which communicates with a webserver using PHP and Volley. My app sends a Post request to a Listener.php file on my webserver and chooses different functions in a Functions.php. The problem is: some functions lead to a volley null error although the code is executed. Theres no error in apache erroglog and I can see the data change in my database. But I want to process a response in my app which is not possible when I get this error. The webserver is running on my raspberry pi now and I get this error all the time when calling specific functions, other functions are working as expected. When I test the same code on Windows its working fine (although these null errors are happening too from time to time at the same functions).
I really hope theres someone to put me in the right direction, I have no idea how to proceed with that kind of problem..

Java/Volley Post



public static void importNewMedia(final Context context) {


final String TAG = "importMedia";
String tag_string_req = "admin_control";
StringRequest strReq = new StringRequest(com.android.volley.Request.Method.POST,
AppConfig.URL_SERVER, new Response.Listener<String>() {



@Override
public void onResponse(String response) {
Log.d(TAG, response.toString());
try {
JSONObject jObj = new JSONObject(response);
boolean error = jObj.getBoolean("error");
if (!error) {

Toast.makeText(context, "Database has been updated!", Toast.LENGTH_SHORT).show();

} else {

Toast.makeText(context,
"Database has not been updated!", Toast.LENGTH_SHORT).show();

}
} catch (JSONException e) {


Toast.makeText(context, "0"+
" Database has not been updated!", Toast.LENGTH_SHORT).show();


e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Connection Error: " + error.getMessage());

}
}) {
protected Map<String, String> getParams() {
HashMap<String ,String> params=new HashMap<String, String>();
params.put("tag", "getNewMedia");
return params;
}
};
// Adding request to request queue
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
System.out.println(strReq + tag_string_req);


}


Listener.php



else if ($tag == 'getNewMedia') {

$db_functions->copyNewMediaToSongs($mysqli);

if ($test ) {

$response["error"] = FALSE;
echo json_encode($response);


} else {

$response["error"] = TRUE;
$response["error_msg"] = "Server Error";
echo json_encode(array_values($response));
}
}


One of the Functions that causes null error



public function copyNewMediaToSongs($mysqli) {


shell_exec('sudo sh /var/www/html/musicbox/include/findmp3.sh');
return 1;

}


What Logcat shows me ...



08-09 04:16:01.420 2812-2979/com.ruecgames.sengproject.musicbox I/System.out: [ ] http://192.168.2.123/musicbox/include/Listener.php 0x85ca2597 NORMAL 18admin_control
08-09 04:16:09.008 2812-2812/com.ruecgames.sengproject.musicbox E/getConfig: Connection Error: null

Answer

Not sure what really solved it (I think its the retry policy I added), but with this code the null error is gone. What found out now, they query im executing takes waay to long, and I dont know why. I post it in another question, link will be in the comments

 public static  void registerUser(final Context context){


    StringRequest stringRequest = new   StringRequest(Request.Method.POST,   AppConfig.URL_SERVER,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    Toast.makeText(context,response,Toast.LENGTH_LONG).show();
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Toast.makeText(context,error.toString(),Toast.LENGTH_LONG).show();
                }
            }){
        @Override
        protected Map<String,String> getParams(){
            Map<String,String> params = new HashMap<String, String>();
            params.put("tag", "getNewMedia");
            return params;
        }

    };

    stringRequest.setRetryPolicy(new DefaultRetryPolicy(
            100000,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

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