SHARE
TWEET

Untitled

a guest Jun 17th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. String login = textousuario.getText().toString();
  2.             String senha = textosenha.getText().toString();
  3.             String urllogin = "http...."
  4.             String tipo = "";
  5.             MecanismoString mecanismoString = new MecanismoString(this, this);
  6.             mecanismoString.execute(tipo, urllogin, login, senha);
  7.      
  8. public class MecanismoString extends AsyncTask <String, String, String> {
  9.  
  10.     private Interfacestring Interfacestring;
  11.     private RequestQueue requestQueue;
  12.     private StringRequest request;
  13.     private Interfacestring execinterface;
  14.  
  15.     String usuario, senha, result;
  16.  
  17.     Context context;
  18.     Toast toast;
  19.  
  20.     public MecanismoString (Context context, Interfacestring execinterface){
  21.         this.context = context;
  22.         this.Interfacestring = execinterface;
  23.     }
  24.  
  25.  
  26.  
  27.  
  28.     @Override
  29.     public String doInBackground(String... params) {
  30.  
  31.         Log.i("Script", "1 ->" + params[0]);
  32.         Log.i("Script", "2 ->" + params[1]);
  33.         Log.i("Script", "3 ->" + params[2]);
  34.         Log.i("Script", "4 ->" + params[3]);
  35.  
  36.         usuario = params[2];
  37.         senha = params[3];
  38.  
  39.         requestQueue = Volley.newRequestQueue(context);
  40.  
  41.         request = new StringRequest(Request.Method.POST, params[1], new Response.Listener<String>() {
  42.             @Override
  43.             public void onResponse(String response) {
  44.                 try {
  45.                     JSONObject jsonObject = new JSONObject(response);
  46.  
  47.                     result = jsonObject.getString("perfil");
  48.  
  49.  
  50.                 } catch (JSONException e) {
  51.                     e.printStackTrace();
  52.                 }
  53.  
  54.             }
  55.         }, new Response.ErrorListener() {
  56.             @Override
  57.             public void onErrorResponse(VolleyError error) {
  58.  
  59.             }
  60.         }){
  61.             @Override
  62.             protected Map<String, String> getParams() throws AuthFailureError {
  63.                 HashMap<String, String> hashMap = new HashMap<String, String>();
  64.                 hashMap.put("login", usuario);
  65.                 hashMap.put("senha", senha);
  66.  
  67.                 return hashMap;
  68.             }
  69.         };
  70.  
  71.         requestQueue.add(request);
  72.  
  73.         return (result);
  74.     }
  75.  
  76.  
  77.     @Override
  78.     protected void onPostExecute(String result) {
  79.  
  80.         execinterface.carregarString(result);
  81.  
  82.     }
  83.  
  84. }
  85.      
  86. public void carregarString(String result) {
  87.  
  88.         Toast.makeText(context.getApplicationContext(),
  89.                 result,
  90.                 Toast.LENGTH_SHORT) .show();
  91.  
  92.     }
  93.      
  94. E/AndroidRuntime: FATAL EXCEPTION: main
  95.     Process: ic.eng.br.eunaobra, PID: 9428
  96.     java.lang.NullPointerException: Attempt to invoke interface method 'void ic.eng.br.eunaobra.Interfacestring.carregarString(java.lang.String)' on a null object reference
  97.         at ic.eng.br.eunaobra.MecanismoString.onPostExecute(MecanismoString.java:94)
  98.         at ic.eng.br.eunaobra.MecanismoString.onPostExecute(MecanismoString.java:22)
  99.         at android.os.AsyncTask.finish(AsyncTask.java:695)
  100.         at android.os.AsyncTask.-wrap1(Unknown Source:0)
  101.         at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:712)
  102.         at android.os.Handler.dispatchMessage(Handler.java:105)
  103.         at android.os.Looper.loop(Looper.java:164)
  104.         at android.app.ActivityThread.main(ActivityThread.java:6944)
  105.         at java.lang.reflect.Method.invoke(Native Method)
  106.         at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
  107.         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top