Advertisement
Guest User

Untitled

a guest
Nov 24th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. URL url = null;
  2. String linea = "";
  3. int respuesta = 0;
  4. StringBuilder resul = null;
  5. try {
  6. url = new URL("http://www.nestel.cl/Login.php?user="+user+"&pass="+pass);
  7. HttpURLConnection conexion= (HttpsURLConnection)url.openConnection();
  8. respuesta=conexion.getResponseCode();
  9.  
  10. resul=new StringBuilder();
  11.  
  12. if (respuesta==HttpURLConnection.HTTP_OK )
  13. {
  14. InputStream in=new BufferedInputStream(conexion.getInputStream());
  15. BufferedReader reader=new BufferedReader(new InputStreamReader(in));
  16.  
  17. while((linea=reader.readLine())!=null)
  18. {
  19. resul.append(linea);
  20. }
  21. }
  22.  
  23. }
  24. catch (Exception e){
  25. Toast.makeText(getApplicationContext(), "error", Toast.LENGTH_LONG).show();
  26. }
  27.  
  28. return resul.toString();
  29. }
  30.  
  31. int respuesta = 0;
  32. try {
  33. JSONArray json = new JSONArray(response);
  34. if(json.length()>0)
  35. {
  36. respuesta = 1;
  37. }
  38. }catch (Exception e){}
  39. return respuesta;
  40. }
  41.  
  42. Thread tr = new Thread(){
  43. @Override
  44. public void run() {
  45. final String resultado = enviardatosGet(mirut.getText().toString(), mipass.getText().toString());
  46. runOnUiThread(new Runnable() {
  47. @Override
  48. public void run() {
  49. int r=obtenerdatosJSON(resultado);
  50. if(r>0){
  51. Intent i = new Intent(getApplicationContext(),menu.class);
  52.  
  53. startActivity(i);
  54. }else{
  55. Toast.makeText(getApplicationContext(), "usuario o pass incorrecto", Toast.LENGTH_LONG).show();
  56. }
  57. }
  58. });
  59. }
  60. };
  61. tr.start();
  62. }
  63.  
  64. Process: com.example.luisalarcon.alumnos, PID: 24002
  65.  
  66. java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
  67. at android.os.Handler.<init>(Handler.java:200)
  68. at android.os.Handler.<init>(Handler.java:114)
  69. at android.widget.Toast$TN.<init>(Toast.java:627)
  70. at android.widget.Toast.<init>(Toast.java:131)
  71. at android.widget.Toast.makeText(Toast.java:431)
  72. at com.example.luisalarcon.alumnos.MainActivity.enviardatosGet(MainActivity.java:67)
  73. at com.example.luisalarcon.alumnos.MainActivity$1.run(MainActivity.java:93)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement