Advertisement
Guest User

Untitled

a guest
May 21st, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.91 KB | None | 0 0
  1. package org.jcloarca.laboratorio2;
  2.  
  3. import android.support.v7.app.AppCompatActivity;
  4. import android.os.Bundle;
  5. import android.util.Log;
  6. import android.view.View;
  7. import android.widget.Button;
  8. import android.widget.EditText;
  9. import android.widget.Toast;
  10.  
  11. import com.android.volley.Request;
  12. import com.android.volley.Response;
  13. import com.android.volley.VolleyError;
  14. import com.android.volley.toolbox.JsonObjectRequest;
  15.  
  16. import org.jcloarca.laboratorio2.volley.WebService;
  17.  
  18. import org.json.JSONArray;
  19. import org.json.JSONObject;
  20.  
  21. import java.util.HashMap;
  22. import java.util.Map;
  23.  
  24. public class LoginActivity extends AppCompatActivity {
  25.  
  26. private Button btnLogin;
  27. private EditText txtEmail, txtPassword;
  28.  
  29. @Override
  30. protected void onCreate(Bundle savedInstanceState) {
  31. super.onCreate(savedInstanceState);
  32. setContentView(R.layout.activity_login);
  33.  
  34. btnLogin = (Button)findViewById(R.id.btnLogin);
  35. txtEmail = (EditText)findViewById(R.id.txtEmail);
  36. txtPassword = (EditText)findViewById(R.id.txtPassword);
  37.  
  38. btnLogin.setOnClickListener(new View.OnClickListener(){
  39. @Override
  40. public void onClick(View v) {
  41. Map<String, String> params = new HashMap<String, String>();
  42. params.put("correo", txtEmail.getText().toString());
  43. params.put("password", txtPassword.getText().toString());
  44. JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, WebService.autenticar, new JSONObject(params), new Response.Listener<JSONObject>() {
  45. @Override
  46. public void onResponse(JSONObject response) {
  47. try{
  48. JSONArray listaUsuarios = response.getJSONArray("user");
  49. if(listaUsuarios.length()>0){
  50. JSONObject user = listaUsuarios.getJSONObject(0);
  51.  
  52. Toast.makeText(getApplicationContext(), "Bienvenido "+user.getString("nombreCompleto"), Toast.LENGTH_LONG).show();
  53. }else{
  54. Toast.makeText(getApplicationContext(), "Verifique sus credenciales.", Toast.LENGTH_LONG).show();
  55. }
  56.  
  57. }catch(Exception ex){
  58. Log.e("Error: ",ex.getMessage());
  59. }
  60. }
  61. }, new Response.ErrorListener(){
  62. @Override
  63. public void onErrorResponse(VolleyError error){
  64. Log.e("Error: Response",error.getMessage());
  65. }
  66. });
  67. WebService.getInstance(v.getContext()).addToRequestQueue(request);
  68. }
  69. });
  70.  
  71. }
  72. }
  73.  
  74. 05-21 16:16:59.990 16961-16961/org.jcloarca.laboratorio2 E/AndroidRuntime: FATAL EXCEPTION: main
  75. Process: org.jcloarca.laboratorio2, PID: 16961
  76. java.lang.NullPointerException: println needs a message
  77. at android.util.Log.println_native_inner(Native Method)
  78. at android.util.Log.println_native(Log.java:290)
  79. at android.util.Log.e(Log.java:416)
  80. at org.jcloarca.laboratorio2.LoginActivity$1$2.onErrorResponse(LoginActivity.java:64)
  81. at com.android.volley.Request.deliverError(Request.java:598)
  82. at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:101)
  83. at android.os.Handler.handleCallback(Handler.java:739)
  84. at android.os.Handler.dispatchMessage(Handler.java:95)
  85. at android.os.Looper.loop(Looper.java:135)
  86. at android.app.ActivityThread.main(ActivityThread.java:5343)
  87. at java.lang.reflect.Method.invoke(Native Method)
  88. at java.lang.reflect.Method.invoke(Method.java:372)
  89. at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
  90. at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
  91. at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:115)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement