【发布时间】:2012-03-30 11:42:26
【问题描述】:
我在 main.java 中写了这段代码
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://way2tutorial.com/json/index.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
}catch(Exception e){
Log.e("log_tag", "Error in http connection"+e.toString());
}
还包括
<uses-permission android:name="android.permission.INTERNET"/>
在清单文件中
但是在http中运行android应用程序报错
connectionandroid.os.NetworkOnMainThreadException
【问题讨论】:
-
剪切并粘贴错误 - 因为它肯定不是您列出的内容
-
发布完整的堆栈跟踪...
-
这不是您原来的错误。发布您的完整 log-cat 值。