elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Recopilación Tutoriales y Manuales Hacking, Seguridad, Privacidad, Hardware, etc


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  Java
| | | |-+  Error con Thread
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Error con Thread  (Leído 1,607 veces)
Baal_30

Desconectado Desconectado

Mensajes: 248



Ver Perfil
Error con Thread
« en: 6 Mayo 2016, 21:12 pm »

Buenas noches, llevo todo el día devanandome los sesos con acceso a una bbdd desde android, he visto que hay que hacerlo desde un thread, he estado mirando y mirando y he hecho como ponían por ahí, pero me da este error y no tengo ni idea ni logro entenderlo, ¿alguien me echa una mano? :D

05-06 19:05:01.836 2097-2201/com.google.android.googlequicksearchbox:search W/Search.SearchUrlHelper: Auth token not ready, no auth header set.
05-06 19:05:01.852 2718-2718/? E/ActivityThread: Service com.android.email.service.EmailBroadcastProcessorService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@6623d1f that was originally bound here
                                                 android.app.ServiceConnectionLeaked: Service com.android.email.service.EmailBroadcastProcessorService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@6623d1f that was originally bound here


En línea

«La suerte es el cuidado de los detalles». -Winston Churchill
Baal_30

Desconectado Desconectado

Mensajes: 248



Ver Perfil
Re: Error con Thread
« Respuesta #1 en: 7 Mayo 2016, 14:13 pm »

Pongo el código con las dos clases (main y la asynctask) a ver si alguien me puede ayudar, el problema es que en el Toast que muestra despues de ejecutar el hilo, siempre me pone "Vacío".

Código
  1.  
  2. public class MainActivity extends AppCompatActivity {
  3.    Button btnEntrar;
  4.    EditText etUsuario;
  5.    EditText etPass;
  6.  
  7.    public static String login = "Vacío";
  8.  
  9.    @Override
  10.    protected void onCreate(Bundle savedInstanceState) {
  11.        super.onCreate(savedInstanceState);
  12.        setContentView(R.layout.activity_main);
  13.  
  14.        btnEntrar = (Button) findViewById(R.id.btnEntrar);
  15.        etUsuario = (EditText) findViewById(R.id.etUsuario);
  16.        etPass = (EditText) findViewById(R.id.etPass);
  17.  
  18.        btnEntrar.setOnClickListener(new View.OnClickListener() {
  19.            @Override
  20.            public void onClick(View v) {
  21.                String usuario = etUsuario.getText().toString();
  22.                String pass = etPass.getText().toString();
  23.                new ConnUsers(usuario, pass).execute();
  24.  
  25.  
  26.                Toast.makeText(MainActivity.this, login, Toast.LENGTH_SHORT).show();
  27.  
  28.                /*if(login){
  29.                     Intent intent = new Intent(MainActivity.this, IncidenciasActivity.class);
  30.                     startActivity(intent);
  31.                     Toast.makeText(MainActivity.this, "Acceso es TRUE", Toast.LENGTH_SHORT).show();
  32.                 }
  33.                 else{
  34.                     Toast.makeText(MainActivity.this, "Acceso es FALSE", Toast.LENGTH_SHORT).show();
  35.                 } */
  36.            }
  37.        });
  38.    }
  39.  
  40.    private class ConnUsers extends AsyncTask <String, String, String>{
  41.  
  42.        private static final String DB_DRIVER = "org.postgresql.Driver";
  43.        private static final String url = "jdbc:postgresql://xxx/xxx";
  44.        private static final String user = "xxx";
  45.        private static final String password = "xxx";
  46.  
  47.        private String usuario;
  48.        private String pass;
  49.  
  50.        public ConnUsers(String usuario, String pass){
  51.            this.usuario = usuario;
  52.            this.pass = pass;
  53.        }
  54.  
  55.        @Override
  56.        protected String doInBackground(String... params) {
  57.            String acceso = "doInBackground";
  58.  
  59.            try{
  60.                Class.forName(DB_DRIVER);
  61.  
  62.                Connection connection = DriverManager.getConnection(url, user, password);
  63.                Statement st = connection.createStatement();
  64.                ResultSet rs = st.executeQuery("SELECT * FROM usuarios WHERE usuario = '" + usuario +"'");
  65.  
  66.                if(rs.next()!=false){
  67.                    if(Funciones.md5(pass).equalsIgnoreCase(rs.getString("password"))){
  68.  
  69.                        int id = rs.getInt("id");
  70.  
  71.                        acceso = "Todo correcto";
  72.                    }
  73.                    else{
  74.                        //Toast.makeText(context, "Password incorrecto", Toast.LENGTH_LONG).show();
  75.                        acceso = "Falla la pass";
  76.                    }
  77.                }
  78.                else{
  79.                    //Toast.makeText(context, "Usuario incorrecto", Toast.LENGTH_LONG).show();
  80.                    acceso = "Falla el usuario";
  81.                }
  82.  
  83.                rs.close();
  84.                st.close();
  85.                connection.close();
  86.  
  87.            }catch(SQLException e){
  88.                cancel(true);
  89.                e.printStackTrace();
  90.            } catch (NoSuchAlgorithmException e) {
  91.                e.printStackTrace();
  92.            } catch (ClassNotFoundException e) {
  93.                e.printStackTrace();
  94.            }
  95.  
  96.            return acceso;
  97.        }
  98.  
  99.        @Override
  100.        protected void onPostExecute(String s) {
  101.            MainActivity.login = s;
  102.        }
  103.  
  104.        @Override
  105.        protected void onCancelled() {
  106.  
  107.        }
  108.    }
  109.  
  110.  
  111. }
  112.  
  113.  

Gracias de antemano.


« Última modificación: 7 Mayo 2016, 14:30 pm por Baal_30 » En línea

«La suerte es el cuidado de los detalles». -Winston Churchill
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines