Pessoal acontece o seguinte…
eu to fazendo uma thread que conecta com o servidor pra aprovar o login…
essa thread é chamada por um função… e essa função retorna se a pesquisa no banco achou o login ou não…
só que acontece que a função retorna o valor antes da minha thread conectar…
eis o código…
public void run(){
try {
try {
loginvar= Conect.Get(user.getString(),senha.getString());
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
catch (IOException ex) {
Alert error = new Alert("Erro ao tentar Conectar", "Por Favor, verifique sua conexão.", null, null);
error.setTimeout(Alert.FOREVER);
user.setString("");
senha.setString("");
midlet.display.setCurrent(error, fmlogin);
}
if (loginvar == true){
midlet.display.setCurrent(midlet.Mapa);
}
else {
Alert error = new Alert("Erro ao tentar Logar!!", "Por Favor, verifique se sua senha ou login estão corretos", null, null);
error.setTimeout(Alert.FOREVER);
user.setString("");
senha.setString("");
midlet.display.setCurrent(error, fmlogin);
}
}
Esse código acima é um Thread que chama a função…esta no num arquivo chamado telalogin.java
eis a função que se encontra no arquivo ServerConnection.java
public boolean Get(String user, String pass) throws IOException, InterruptedException{
boolean ret= false;
Thread thread = new Thread();
try{
urllogin ="http://localhost:8084//conectionServelet/locationbd";
urllogin = urllogin+"?"+"user="+user+"&"+"pass="+pass;
thread.start();
thread.join();
is = hc.openInputStream();
ret = loginprocess(hc, is);
} finally{
quit=true;
System.out.println("Ret no retorno="+ret);
return ret;
}
// if(ret == false)
// showAlerta(ErroMsg);
}
agora a thread de conexão
public void run() {
while(!quit){
try {
hc = (HttpConnection) Connector.open(urllogin);
hc.setRequestMethod(HttpConnection.GET);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}