So I'm really new to this. I was following a tutorial on web that showed how to connect these two. But everything I do it just jumps to catch part and it says "No connection". What am I missing? I also connect to a http server to use a PHP script which queries username and password from the database.
try
{
nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("username", username));
nameValuePairs.add(new BasicNameValuePair("password", password));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
response = httpClient.execute(httpPost);
if(response.getStatusLine().getStatusCode()==200)
{
entity = response.getEntity();
if(entity != null)
{
InputStream instream = entity.getContent();
JSONObject jsonResponse = new JSONObject(instream.toString());
String retUser = jsonResponse.getString("upime");
String retPass = jsonResponse.getString("geslo");
if(username.equals(retUser) && password.equals(retPass))
{
SharedPreferences sp = getSharedPreferences("logindetails", 0);
SharedPreferences.Editor spedit = sp.edit();
spedit.putString("upime", username);
spedit.putString("geslo", password);
spedit.commit();
Toast.makeText(getBaseContext(), "Login successful", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(getBaseContext(), "Failed to login", Toast.LENGTH_SHORT).show();
}
}
}
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getBaseContext(), "No connection", Toast.LENGTH_LONG).show();
}