Uygulamam için bir giriş işlevi yazıyorum ve aniden bu hatayı almaya başladım: org.json.JSONException: Value Connection of type java.lang.String cannot be converted to JSONObject
Kodu burada değiştirmeyi hatırlamıyorum hiç ve daha önce çalışırdı. Android stüdyosunda hata ayıklama modunu kullanmaya başladığımda aniden çalışmayı bıraktım. İşte org.json.JSONException: Değer java.lang.String Bağlantısı JSONObject
private String loginUrl = "http://10.0.2.2/user/login.php";
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
request = new StringRequest(Request.Method.POST, loginUrl, new Response.Listener<String>() /*ERROR*/ {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response); /*ERROR*/
if (jsonObject.names().get(0).equals("success")) {
Toast.makeText(getApplicationContext(), jsonObject.getString("success"), Toast.LENGTH_SHORT).show();
email.setText("");
password.setText("");
Log.d("test", "Going to Main.class");
startActivity(new Intent(MainActivity.this, Main.class));
//setContentView(R.layout.activity_main);
} else {
Toast.makeText(getApplicationContext(), jsonObject.getString("error"), Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("email", email.getText().toString());
parameters.put("password", password.getText().toString());
return parameters;
}
};
requestQueue.add(request);
}
});
'response' değeri nedir içermediği anlamına gelir? –