IllegalStateException:在openConnection之后已经连接

时间:2014-10-20 19:57:23

标签: java android httpurlconnection urlconnection

我试图在我的HttpURLConnection中设置DOOutput,但我一直得到这个该死的异常,我不知道该怎么办,因为代码基本上是来自网络的CTRL + C / V!检查出来:

url = new URL(Constants.Shared.API_URL+"registration");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);//BOOM!

在我执行conn.setDoOutput之后,我获得了一个免费的catch区块门票,例外是java.lang.IllegalStateException: Already connected

有趣的是,即使google documentation(请参阅发布内容部分)也告诉我要像我一样做!我在这做错了什么?!?

编辑1:堆栈跟踪
[java.net.URLConnection.checkNotConnected(URLConnection.java:464),java.net.URLConnection.setDoOutput(URLConnection.java:878),br.com.aec.acs.service.IntegracaoService.RegisterCloudUser(IntegracaoService.java:118 ),br.com.aec.acs.service.IdentityService.RegisterNewACS(IdentityService.java:49),br.com.aec.acs.RegistrationActivity.ButtonOkClicked(RegistrationActivity.java:40),br.com.aec.acs。 RegistrationActivity_ $ 1.onClick(RegistrationActivity_.java:52),android.view.View.performClick(View.java:4240),android.view.View $ PerformClick.run(View.java:17721),android.os.Handler。 handleCallback(Handler.java:730),android.os.Handler.dispatchMessage(Handler.java:92),android.os.Looper.loop(Looper.java:137),android.app.ActivityThread.main(ActivityThread.java) :5103),java.lang.reflect.Method.invokeNative(Native Method),java.lang.reflect.Method.invoke(Method.java:525),com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit .java:737),com.android.internal.os.ZygoteInit.main(ZygoteInit。 java:553),dalvik.system.NativeStart.main(Native Method)]

0 个答案:

没有答案