0
public void searchLoginInfo(View view) {
    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, showUrl,null,new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            try {
                JSONArray users = response.getJSONArray("users");
                for (int i = 0; i < users.length(); i++){
                    JSONObject user = users.getJSONObject(i);
                    String username = user.getString("username").toLowerCase();
                    String password = user.getString("password".toLowerCase());
                    String retypedpassword = user.getString("retypedpassword");
                    String email = user.getString("email");
                    if (username.equals(myLoginList.get(0)) && password.equals(myLoginList.get(1))) {
                        Toast.makeText(LoginActivity.this, "Login Succesfull", Toast.LENGTH_LONG).show();
                        Intent send = new Intent(LoginActivity.this, WelcomeActivity.class);
                        startActivity(send);
                        break;
                    }else{
                        Toast.makeText(LoginActivity.this, "Login Failed!", Toast.LENGTH_LONG).show();
                        Intent send = new Intent(LoginActivity.this, LoginActivity.class);
                        startActivity(send);
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e("Volley Error", error.toString());
            NetworkResponse networkResponse = error.networkResponse;
            if (networkResponse != null) {
                Log.e("Status code", String.valueOf(networkResponse.statusCode));
            }
        }
    });
    requestQueue.add(jsonObjectRequest);
}

I am using a JSON object request to get information from a database that I have created. I am able with my android application to insert data into the database but now I want to check for example if the user created an user account. Both the url and the php files work fine. I have used a log in the onErrorResponse method to see what is the actual error and I got this: E/Volley Error: com.android.volley.ParseError: org.json.JSONException: Value Connection of type java.lang.String cannot be converted to JSONObject. I do not know what seems to be the problem with this. I have also checked using postamn if my web service is returning json data.Printscreen with the json data Can anybody help me? Thanks in advance

3
  • Sounds like Volley can't convert to json whatever string you're passing it. We'd really need to see what's being passed to Volley to determine what is wrong with it. Commented Nov 7, 2016 at 0:45
  • @saywhatnow how do I do that? Commented Nov 7, 2016 at 11:18
  • At every step, Log.debug the data so you can see what you're actually working with. If you ever don't understand why something is behaving in a particular way, look at it in smaller pieces. :) Commented Nov 7, 2016 at 19:41

2 Answers 2

1

Instead of JSONRequest try StringRequest and check if your response is valid json or not. JSONRequest tries to parse String into JSONObject and then returns and this will fail if response is not of type JSON.

Sign up to request clarification or add additional context in comments.

Comments

0

You need to test if you web service return a values. You can test this with your navigator or with Postman for example.

5 Comments

I did that using postman and it returns json data. I have uploaded a photo. @SofDroid
You should be modify the ' JsonObjectRequest ' object with ' JsonArrayRequest '
And JSONObject with JSONArray
I did that and I got exactly the same error. The only difference is that now it says that the string cannot be converted to JSONArray insead of JSONObject as it previously did.
So, you have a error in your web server Json structor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.