I am creating an Android application, but so far (if?) The server is not found, it will hang up a toolbox (SDK / emulator?). I have attached my login code. Please help me find a solution. I just want that if the server is unavailable, my application will remain on the login page without hanging itself.
when I debugged my code, I did not get the httpResponse value and after this line
HttpResponse httpResponse = httpclient.execute(httpPost);
there was a problem
public String login(String userName, String password){ try { String url = URL+ "?flag="+"on"+"&user="+userName+"&pass="+password; httpPost = new HttpPost(url); HttpResponse httpResponse = httpclient.execute(httpPost); int statuscode = httpResponse.getStatusLine().getStatusCode(); if (statuscode == 200) { String responseMsg = getResponse(httpResponse); return responseMsg; }else{ Log.e(TAG, statuscode+""); } } catch (ClientProtocolException e) { Log.e(TAG, e.getMessage(),e); } catch (IOException e) { Log.e(TAG, e.getMessage(),e); } return null; }
source share