Click here to Skip to main content
14,879,028 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to send userid to server and fetch the data related to the userid in android using Volley connectivity and php script But i am getting Error like :
com.android.volley.ParseError: org.json.JSONException: Value UserId of type java.lang.String cannot be converted to JSONObject

other Error Like :End of Input character 0 of

Help me to Solve the problem...

What I have tried:

Below is php file

<?php

    require "connect.php";
    
    $userId = $_GET['UserId'];
    
    $query = "SELECT * FROM `executive` WHERE ExecutiveId = '$userId'";
 
    $result = mysqli_query($conn, $query);
    
    if(mysqli_num_rows($result) > 0){
        while($row = mysqli_fetch_assoc($result)){
           echo json_encode($row);
        }
    } else {
        echo "UserId :".$userId."Not Found";
    }
	mysqli_close($conn);

?>


Below code is from android file

public void getExecutiveInfo(){

        String url = "https://sampleappdatabase.000webhostapp.com/SmartKids/ExecutiveInfo.php";

        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {

                Log.d("Reponse", response.toString());

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.d("Error Response", error.toString());
            }
        }){

            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String,String> params = new HashMap<>();
                params.put("UserId",UserId);
                return params;
            }
        };

        Singleton.getInstance(getApplicationContext()).addToRequestque(jsonObjectRequest);

    }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900