Galera tudo bem ? Infelizmente em um dos passos do meu código está dando pau, mais especificamente:
HttpResponse resposta = client.execute(post);
meu código:
Pirmeiro, o webClient
'imports....'
public class WebClient {
private String url;
public WebClient(String url){
this.url = url;
}
public String post(String json) {
try {
HttpPost post = new HttpPost(url);
post.setEntity(new StringEntity(json));
post.setHeader("Content-type", "application/json");
post.setHeader("Accept", "application/json");
HttpClient client = new DefaultHttpClient();
Thread.sleep(3000,0);// pra ver a barra e prograsso
HttpResponse resposta = client.execute(post);
Log.i("resposta deu certo ", " post !!!!");
return EntityUtils.toString(resposta.getEntity());
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
return "Deu certo foi !@#$%¨&*!";
}
}
O erro é no código acima, na linha HttpResponse resposta = client.execute(post);
e o erro: 04-05 03:30:42.118 4672-4691/com.example.daviguanabara.cadastrocaelum E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #1 Process: com.example.daviguanabara.cadastrocaelum, PID: 4672 java.lang.RuntimeException: An error occured while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:300) at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355) at java.util.concurrent.FutureTask.setException(FutureTask.java:222) at java.util.concurrent.FutureTask.run(FutureTask.java:242) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) at java.lang.Thread.run(Thread.java:818) Caused by: java.lang.SecurityException: Permission denied (missing INTERNET permission?) at java.net.InetAddress.lookupHostByName(InetAddress.java:451) at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252) at java.net.InetAddress.getAllByName(InetAddress.java:215) at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137) at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465) at agenda.suporte.WebClient.post(WebClient.java:48) at agenda.task.EnviaContatoTask.doInBackground(EnviaContatoTask.java:58) at android.os.AsyncTask$2.call(AsyncTask.java:288) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) at java.lang.Thread.run(Thread.java:818) Caused by: android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname) at libcore.io.Posix.android_getaddrinfo(Native Method) at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:55) at java.net.InetAddress.lookupHostByName(InetAddress.java:438) at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252) at java.net.InetAddress.getAllByName(InetAddress.java:215) at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137) at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465) at agenda.suporte.WebClient.post(WebClient.java:48) at agenda.task.EnviaContatoTask.doInBackground(EnviaContatoTask.java:58) at android.os.AsyncTask$2.call(AsyncTask.java:288) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) at java.lang.Thread.run(Thread.java:818) Caused by: android.system.ErrnoException: android_getaddrinfo failed: EACCES (Permission denied) at libcore.io.Posix.android_getaddrinfo(Native Method) at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:55) at java.net.InetAddress.lookupHostByName(InetAddress.java:438) at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252) at java.net.InetAddress.getAllByName(InetAddress.java:215) at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137) at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119) at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465) at agenda.suporte.WebClient.post(WebClient.java:48) at agenda.task.EnviaContatoTask.doInBackground(EnviaContatoTask.java:58) at android.os.AsyncTask$2.call(AsyncTask.java:288) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) at java.lang.Thread.run(Thread.java:818) 04-05 03:30:43.655 4672-4672/com.example.daviguanabara.cadastrocaelum E/WindowManager﹕ android.view.WindowLeaked: Activity agenda.activity.ListaAlunosActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{5dc9ec9 V.E..... R......D 0,0-1026,486} that was originally added here at android.view.ViewRootImpl.(ViewRootImpl.java:363) at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:261) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69) at android.app.Dialog.show(Dialog.java:298) at android.app.ProgressDialog.show(ProgressDialog.java:116) at android.app.ProgressDialog.show(ProgressDialog.java:99) at android.app.ProgressDialog.show(ProgressDialog.java:94) at agenda.task.EnviaContatoTask.onPreExecute(EnviaContatoTask.java:41) at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:587) at android.os.AsyncTask.execute(AsyncTask.java:535) at agenda.activity.ListaAlunosActivity.onOptionsItemSelected(ListaAlunosActivity.java:125) at android.app.Activity.onMenuItemSelected(Activity.java:2882) at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:1127) at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:761) at com.android.internal.view.menu.SubMenuBuilder.dispatchMenuItemSelected(SubMenuBuilder.java:81) at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152) at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:904) at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:894) at com.android.internal.view.menu.MenuPopupHelper.onItemClick(MenuPopupHelper.java:179) at android.widget.AdapterView.performItemClick(AdapterView.java:300) at android.widget.AbsListView.performItemClick(AbsListView.java:1143) at android.widget.AbsListView$PerformClick.run(AbsListView.java:3044) at android.widget.AbsListView$3.run(AbsListView.java:3833) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5221) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 04-05 03:30:45.248 4672-4691/com.example.daviguanabara.cadastrocaelum I/Process﹕ Sending signal. PID: 4672 SIG: 9
Galera, to usando o android Studio. Realmente não sei o motivo do erro, Obrigado