• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Error - android.os.NetworkOnMainThreadException

gimomars

Lurker
Hi I'm new with android development, I'm trying to create a simple CRUD using WCF. But I've received the error : android.os.NetworkOnMainThreadException. I think there's a problem in threading.

Can you help me guys? Here's my code. The error occur here :
HttpResponse httpResponse = httpClient.execute(httpGet);

public boolean verifyLogin(String username)
{
try
{
DefaultHttpClient httpClient = new DefaultHttpClient();

HttpGet httpGet = new HttpGet("http://localhost:89/Service1.svc/checkLogin?name="+ username +"");
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
InputStream stream = httpEntity.getContent();
String result = convertStreamToString(stream);

if (result.charAt(1) == '1')
{
Toast.makeText(getApplicationContext(), "Success", Toast.LENGTH_LONG);
return true;
}
else
{
return false;
}
}
catch(Exception e)
{
return false;
}
}

Thanks
 
Back
Top Bottom