Trying To Upload To Dropbox: NetworkOnMainThreadException?

£可爱£侵袭症+ 提交于 2019-11-28 02:06:04

Prior to Honeycomb SDK, it was allowed to perform network operation on the main thread. However, with Honeycomb, it is no longer allowed and a NetworkOnMainThreadException is thrown if a network operation is attempted in main/UI thread.

You need to perform network operations in a different thread. You can take a look at AsyncTask to achieve the same.

My guess is, the error caused by StrictMode.ThreadPolicy. you can't access network in the same UI thread.

try adding these lines to your code in oncreate

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); 
StrictMode.setThreadPolicy(policy);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!