Je fais le didacticiel de connexion android en utilisant volley de android hive. mais quand je l'ai essayé, il ira à l'erreur de volée, je ne sais pas pourquoi, je suis juste un débutant dans android. Aidez-moi, s'il vous plaît. . Je cours mon projet dans un émulateur et le relie en utilisant le debug usb. Mon émulateur est NOX.android login volley erreur
J'ai déjà terminé la configuration de la base de données.
Une fois connecté, je veux intention ma classe de tableau de bord, mais il n'a pas l'intention, il va avec ces erroe ci-dessous
Voici le code où l'erreur est:
public void onErrorResponse(VolleyError error) {
//Log.e(TAG, "Login Error: " + error.getMessage());
Toast.makeText(Login.this,
"VOLLEY ERROR", Toast.LENGTH_LONG).show();
hideDialog();
}
et le code complet de cette classe qui est:
package com.example.codeboxjohn.clinic.activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.example.codeboxjohn.clinic.R;
import com.example.codeboxjohn.clinic.app.AppConfig;
import com.example.codeboxjohn.clinic.app.AppController;
import com.example.codeboxjohn.clinic.helper.SessionManager;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
public class Login extends AppCompatActivity {
private Button btnLogin;
private EditText inputUsername;
private EditText inputPassword;
private ProgressDialog pDialog;
private SessionManager session;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
btnLogin = (Button)findViewById(R.id.btnLogin);
inputUsername = (EditText) findViewById(R.id.editTextUsername);
inputPassword = (EditText) findViewById(R.id.editTextPassword);
pDialog = new ProgressDialog(this);
pDialog.setCancelable(false);
//login
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String username = inputUsername.getText().toString().trim();
String password = inputPassword.getText().toString().trim();
if(!username.isEmpty() && !password.isEmpty()) {
checkLogin(username, password);
} else {
Toast.makeText(getApplicationContext(),"Please enter the credentials!", Toast.LENGTH_SHORT).show();
}
}
});
}
private void checkLogin(final String username, final String password) {
//Tag used to cancel the request
String tag_string_req = "req_login";
pDialog.setMessage("Logging in..");
showDialog();
StringRequest strReq = new StringRequest(Request.Method.POST,
AppConfig.URL_LOGIN, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
//Log.d(TAG, "Login Response: " + response.toString());
hideDialog();
try {
JSONObject jObj = new JSONObject(response);
boolean error = jObj.getBoolean("error");
// Check for error node in json
if (!error) {
// user successfully logged in
// Create login session
session.setLogin(true);
// Inserting row in users table
// Launch main activity
Intent intent = new Intent(Login.this,
Dashboard.class);
startActivity(intent);
finish();
} else {
// Error in login. Get the error message
String errorMsg = jObj.getString("error_msg");
Toast.makeText(getApplicationContext(),
"ERROR KO", Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
// JSON error
e.printStackTrace();
Toast.makeText(getApplicationContext(), "Json error: " + response.toString(), Toast.LENGTH_LONG).show();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
//Log.e(TAG, "Login Error: " + error.getMessage());
Toast.makeText(Login.this,
"VOLLEY ERROR", Toast.LENGTH_LONG).show();
hideDialog();
}
}) {
@Override
protected Map<String, String> getParams() {
// Posting parameters to login url
Map<String, String> params = new HashMap<String, String>();
params.put("username", username);
params.put("password", password);
return params;
}
};
// Adding request to request queue
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
}
private void showDialog() {
if(!pDialog.isShowing())
pDialog.show();
}
private void hideDialog() {
if(pDialog.isShowing())
pDialog.dismiss();
}
}
quelle est l'erreur que vous obtenez? –
que monsieur .. erreur de volée. –
montre la pile. – HaroldSer