• 6

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

Code in java class:

public String POST(String url, final Map<String, String> params, final VolleyCallBack callBack) {

        //RequestFuture<String> requestFuture = new RequestFuture.newFuture();
        RequestFuture<String> future = RequestFuture.newFuture();
        progressDialog = new ProgressDialog(context);
        StringRequest stringRequest = new StringRequest(

                new Response.Listener<String>() {
                    public void onResponse(String response) {
                        try {
                            JSONObject jsonObject = new JSONObject(response);

                            val = jsonObject.getString("message");
                        } catch (JSONException e) {
                }, new Response.ErrorListener() {
            public void onErrorResponse(VolleyError error) {
                ToastMsg(error.getMessage() + " " + error.getStackTrace()[0]);
        ) {
            protected Map<String, String> getParams() {
                return params;

        RetryPolicy mRetryPolicy = new DefaultRetryPolicy(

        RequestQueue requestQueue = Volley.newRequestQueue(context);

        return val;

Code in Activity Class:

val = db.POST(Constants.URL_FacultyLogin, map);

For the 1st time when I click on the button I'm not getting a response from the server but 2nd I'm getting a response can anyone help me out why not for the 1st time.

    • Another victim of asynchronous call . StringRequest is an asynchronous call and you just returned a null val cause its modifying inside onResponse.
      • 1
    • I see you are already using a callback like callBack.onSuccess();. So you do not need to return from method Just provide a callback method in both cases success and failure .
      • 1
    • if write the same code in activity class means I'm getting a response for the 1st time but why it is not working from java class file to activity class
      • 2
    • The reason its not working for first time is maybe you have declared val as global variable.

The solution is to use asynctask Refer this

        protected String doInBackground(String... params) {
            //Call your volley function here

        protected void onPostExecute(String result) {
        //The result variable holds your val returned from volley 
  • 1
Reply Report
    • if write the same code in activity class means I'm getting a response for the 1st time but why it is not working from java class file to activity class
      • 1
    • Not getting response from the server on first-time click of a button but 2nd click on button im getting response so that is my issue
      • 1
    • This is because volley uses worker thread and the response takes time and before response is returned your method is returning string which is null.