Dies ist der Code:Verbindung zum Server mit Android mit PHP
public boolean add(){
HttpClient cliente;
List<NameValuePair> lista;
HttpPost post;
cliente = new DefaultHttpClient();
post = new HttpPost("http://pruebamysqlandroid.esy.es/conexion/conexion.php");
lista = new ArrayList<NameValuePair>(3);
lista.add(new BasicNameValuePair("name", contactname.getText().toString()));
lista.add(new BasicNameValuePair("numbretlf", tlf.getText().toString()));
lista.add(new BasicNameValuePair("email", email.getText().toString()));
try{
post.setEntity(new UrlEncodedFormEntity(lista));
cliente.execute(post);//here is the error
return true;
}catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
Wenn ich versuche, den Kontakt zum Server hinzuzufügen ein Fehler lassen Lassen Sie mich nicht mir geholfen hat bitte
Der Fehler ist:
android.os.NetworkOnMainThreadException
Mögliche duplicate of [Wie android.os.NetworkOnMainThreadException zu beheben?] (Http://stackoverflow.com/questions/6343166/how-to-fix-android-os-networkonmainthreadexception) –
Versuchen Sie diese volley libraray es behält die Warteschlangen von Ihnen Anfrage und behandelt andere Angelegenheiten sehr effektiv http://developer.android.com/training/volley/index.html –