NetworkOnMainThreadException

引起问题的 部分   加入线程中运行

new Thread(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub

			}
		}).start();

NetworkOnMainThreadException

02-25 14:50:57.420: E/AndroidRuntime(16377): android.os.NetworkOnMainThreadException

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1128)

02-25 14:50:57.420: E/AndroidRuntime(16377): at java.net.InetAddress.lookupHostByName(InetAddress.java:385)

02-25 14:50:57.420: E/AndroidRuntime(16377): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)

02-25 14:50:57.420: E/AndroidRuntime(16377): at java.net.InetAddress.getAllByName(InetAddress.java:214)

02-25 14:50:57.420: E/AndroidRuntime(16377): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)

02-25 14:50:57.420: E/AndroidRuntime(16377): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)

02-25 14:50:57.420: E/AndroidRuntime(16377): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)

02-25 14:50:57.420: E/AndroidRuntime(16377): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)

02-25 14:50:57.420: E/AndroidRuntime(16377): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)

02-25 14:50:57.420: E/AndroidRuntime(16377): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:315)

02-25 14:50:57.420: E/AndroidRuntime(16377): at libcore.net.http.HttpEngine.connect(HttpEngine.java:310)

02-25 14:50:57.420: E/AndroidRuntime(16377): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)

02-25 14:50:57.420: E/AndroidRuntime(16377): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)

02-25 14:50:57.420: E/AndroidRuntime(16377): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)

02-25 14:50:57.420: E/AndroidRuntime(16377): at java.net.URLConnection.getContent(URLConnection.java:190)

02-25 14:50:57.420: E/AndroidRuntime(16377): at java.net.URL.getContent(URL.java:447)

02-25 14:50:57.420: E/AndroidRuntime(16377): at com.huashang.huishang.utils.AsynImageLoader.loadImageFromUrl(AsynImageLoader.java:62)

02-25 14:50:57.420: E/AndroidRuntime(16377): at com.huashang.huishang.activity.adapter.PageMessageListAdapter.getView(PageMessageListAdapter.java:97)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.widget.AbsListView.obtainView(AbsListView.java:2429)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.widget.ListView.makeAndAddView(ListView.java:1769)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.widget.ListView.fillDown(ListView.java:672)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.widget.ListView.fillFromTop(ListView.java:733)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.widget.ListView.layoutChildren(ListView.java:1608)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.widget.AbsListView.onLayout(AbsListView.java:2264)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.view.View.layout(View.java:13873)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.view.ViewGroup.layout(ViewGroup.java:4500)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1649)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1638)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.widget.LinearLayout.onLayout(LinearLayout.java:1422)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.view.View.layout(View.java:13873)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.view.ViewGroup.layout(ViewGroup.java:4500)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.view.View.layout(View.java:13873)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.view.ViewGroup.layout(ViewGroup.java:4500)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.view.View.layout(View.java:13873)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.view.ViewGroup.layout(ViewGroup.java:4500)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1649)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1507)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.widget.LinearLayout.onLayout(LinearLayout.java:1420)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.view.View.layout(View.java:13873)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.view.ViewGroup.layout(ViewGroup.java:4500)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.view.View.layout(View.java:13873)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.view.ViewGroup.layout(ViewGroup.java:4500)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1649)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1507)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.widget.LinearLayout.onLayout(LinearLayout.java:1420)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.view.View.layout(View.java:13873)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.view.ViewGroup.layout(ViewGroup.java:4500)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.view.View.layout(View.java:13873)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.view.ViewGroup.layout(ViewGroup.java:4500)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1941)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1762)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1072)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4297)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.view.Choreographer.doCallbacks(Choreographer.java:555)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.view.Choreographer.doFrame(Choreographer.java:525)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.os.Handler.handleCallback(Handler.java:615)

02-25 14:50:57.420: E/AndroidRuntime(16377): at android.os.Handler.dispatchMessage(Handler.jav

时间: 2024-11-03 11:28:36

NetworkOnMainThreadException的相关文章

[Android]NetworkOnMainThreadException

好久不写Android代码手都生了,找出自己之前写的程序发现跑不了了,也没啥特别的错误提示,就看到一句有用的错误Caused by: android.os.NetworkOnMainThreadException,查了下原因上在4.0之后在主线程里面执行Http请求都会报这个错,大概是怕Http请求时间太长造成程序假死的情况吧. 解决办法有两个思路,分别是: 第一种方法:直接忽视,强制使用(强烈不推荐,但是修改简单) 在MainActivity文件的setContentView(R.layout

Android3.0版本以上出现android.os.NetworkOnMainThreadException异常与处理方式

http://www.cnblogs.com/awenhome/archive/2012/01/04/2311659.html 以前用2.2 访问WebService没有问题,到3.0上访问出现android.os.NetworkOnMainThreadException 找了资料经过实践,解决方法如下: StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectDiskReads().detectDiskWr

networking-出现android.os.NetworkOnMainThreadException异常

问题描述 出现android.os.NetworkOnMainThreadException异常 当我运行我的android工程时,下边的代码中我得到了一个错误 URL url= new URL(urlToRssFeed); SAXParserFactory factory =SAXParserFactory.newInstance(); SAXParser parser=factory.newSAXParser(); XMLReader xmlreader=parser.getXMLReade

udp-android异常NetworkOnMainThreadException

问题描述 android异常NetworkOnMainThreadException 我通过主Activity调用一个service 在service里面开启了一个线程,通过它发送UDP包,然后就报错了.我百度说是Android为了防止网络请求时间过长而导致界面假死的情况发搜索生,可以用线程来操作网络请求.但是我用的就是线程啊.求帮助.或者可以加Q328940026.谢谢 解决方案 那个据说确实是谷歌设定的 解决方案: 自己写个类继承android.os.AsyncTask,在doInBackg

android.os.NetworkOnMainThreadException

问题描述 android.os.NetworkOnMainThreadException package com.demo.clientdemo; import java.io.IOException;import java.io.InputStream; import org.apache.http.HttpResponse;import org.apache.http.client.ClientProtocolException;import org.apache.http.client.H

Caused by: android.os.NetworkOnMainThreadException错误解决办法

好久不写Android代码手都生了,找出自己之前写的程序发现跑不了了,也没啥特别的错误提示,就看到一句有用的错误Caused by: android.os.NetworkOnMainThreadException,查了下原因上在4.0之后在主线程里面执行Http请求都会报这个错,大概是怕Http请求时间太长造成程序假死的情况吧. 解决办法有两个思路,分别是: 第一种方法:直接忽视,强制使用(强烈不推荐,但是修改简单) 在MainActivity文件的setContentView(R.layout

Android 关于“NetworkOnMainThreadException”问题的原因分析及解决办法_Android

网络收集的原因如下,以及解决办法: 我补充总结一下: 解决办法一: 在操作网络类(socket连接)的activity的protected void onCreate(Bundle savedInstanceState)函数后面加上下面的代码.在super.onCreate(savedInstanceState);前面加. StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectDiskReads().det

Android 关于“NetworkOnMainThreadException”问题的原因分析及解决办法

网络收集的原因如下,以及解决办法: 我补充总结一下: 解决办法一: 在操作网络类(socket连接)的activity的protected void onCreate(Bundle savedInstanceState)函数后面加上下面的代码.在super.onCreate(savedInstanceState);前面加. StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectDiskReads().det

socket-android模拟器运行正常,真机测试程序崩溃

问题描述 android模拟器运行正常,真机测试程序崩溃 一个按钮,点击调用shut_code发送信息.shut_code贴上: private void shut_code() { String msg= "shutdown"; int port = 8099; DatagramSocket s = null; try{ s = new DatagramSocket(); }catch(SocketException e){ e.printStackTrace(); } InetAd