It turns out that when I want to show a message through Toast and send it the context I get an error, I do it like this:
public void mostrarMascotas(){
new Thread(new Runnable() {
@Override
public void run() {
try {
Connection con = new Conexion().getConexion();
Statement stm = con.createStatement();
ResultSet rs = stm.executeQuery("SELECT * FROM tbl_mascota");
String cadena = "";
while (rs.next()){
cadena += rs.getString("mascota_nombre")+"\n";
}
Toast.makeText(this, cadena, Toast.LENGTH_LONG).show();// Aqui me sale el error
}
catch (Exception exp) {
System.out.println("Error al conectarse con la BD: "+ exp.getMessage());
}
}
}).start();
}
in the Toast when changing the context this
by getApplicationContext()
no longer throws me an error, but when running the application and I execute this method the application is closed ....
The strange thing is that replacing the Toask.makeText
with a System.out.println (string) works perfectly for me and gets me the data I need from the Database.