Only the original thread that created a view hierarchy can touch its views
在调试软件的时候出现如下的错误:
01-05 20:53:36.492: E/ZZShip(2043): android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
又是一个ThreadException,之前也碰到过。
解决方法:
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
//这里可以做一些,比如关闭加载对话框
}
}
//--------------------------------------------------------------------
try {
new Thread(new Runnable() {
@Override
public void run() {
try {
//打开加载对话框
//与服务器进行通讯
mHandler.post(runnableUI);
} catch (Exception e) {
Log.e(TAG, e.toString());
}
}
}).start();
} catch (Exception e) {
Log.e(TAG, e.toString());
}
//--------------------------------------------------------------------
// 构建Runnable对象,在runnable中更新界面
Runnable runnableUI=new Runnable(){
@Override
public void run() {
//更新UI
mHandler.sendEmptyMessage(1);//更新完成以后,发送对话框关闭加载对话框
}
};
Only the original thread that created a view hierarchy can touch its views的更多相关文章
- 开发错误记录1:解决:Only the original thread that created a view hierarchy can touch its views.
今天在项目中要使用圆角头像,导入开源 CircleImageView ,然后setImageBitmap()时 运行时就会发现,它会报一个致命性的异常:: · ERROR/AndroidRuntime ...
- 浅析Android中的消息机制-解决:Only the original thread that created a view hierarchy can touch its views.
在分析Android消息机制之前,我们先来看一段代码: public class MainActivity extends Activity implements View.OnClickListen ...
- Android: Only the original thread that created a view hierarchy can touch its views 异常
最近自己再写一个小项目练手,创建一个线程从网络获取数据然后显示在 recyclerView 上.写好后发现页面能够显示,但是有时候会把请求的数据显示过来,有时候不会.点开 android monito ...
- Only the original thread that created a view hierarchy can touch its views解决办法
这周操作系统作业布置了一个作业,内容是做个小软件,来模拟消费者生产者问题,作业实现起来不来,因为之前写过这个算法,所以关键步骤就是在消费和生产的时候更新缓存区的UI控件就行,之后问题就来了,出现了标题 ...
- 错误:Only the original thread that created a view hierarchy can touch its views——Handler的使用
在跟随教程学习到显示web页面的html源码时报错:Only the original thread that created a view hierarchy can touch its views ...
- 子线程调用invalidate()产生“Only the original thread that created a view hierarchy can touch its views.”原因分析
目录 1.异常出处 2.从View.invalidate()方法开始分析 3.ViewRootImpl如何与View进行关联:从Activity的setContentView开始分析 3.1 最顶层的 ...
- andriod 错误:Only the original thread that created a view hierarchy can touch its views——Handler的使用
package com.example.yanlei.myapplication; import android.media.MediaMetadataRetriever; import androi ...
- 解决Only the original thread that created a view hierarchy can touch its views
这种异常出现在子线程中处理UI操作产生的异常,将UI操作放在主线程中就OK了
- "Only the original thread that created a view hierarchy can touch its views.” 解决方法
这个主要总是,开启的线程和 UI 线程(主线程)不是同一个线程.可以Runnable方式避免,如下例所示就可以解决这个问题了. public static void updateText(Activi ...
随机推荐
- JPA注释,内嵌数据对象
@Data @Embeddable @NoArgsConstructor @AllArgsConstructor @JsonNaming(value = LowerCaseWithUnderscore ...
- Mac下启动Apache
1.启动 sudo apachectl -k start 2.重新启动 sudo apachectl -k restart //-------------------------------- ...
- js实现刮刮卡效果
<!DOCTYPE html> <html> <body> <canvas/> <script> (function(bodyStyle) ...
- scikit-learn点滴
scikit-learn点滴 scikit-learn是非常漂亮的一个机器学习库,在某些时候,使用这些库能够大量的节省你的时间,至少,我们用Python,应该是很难写出速度快如斯的代码的. sciki ...
- img与父元素的间隙解决
近来在做H5页面时,突然发现一个问题,使用一个div包裹一个img,在手机预览时,发现图片与div之间有间隙. 当时第一反应就是,是不是间距没有设置为0,于是预览了下代码: .active img { ...
- 对XML的操作
对XML的操作主要使用到的语法示例: using System.Xml; private static string XmlMarketingStaff = AppDomain.CurrentDoma ...
- EF4.1之Code first 的几种连接数据库的方式
通过代码 进行连接和创建数据库的方法主要分为两种: 1.使用用连接字符串(在配置文件里面): 连接字符串: <add name="DbEntities" connection ...
- asp.net字符串分割函数用法
先来看个简单的实例 但是其数组长度却是25,而不是3.下面这种方法是先将“[111cn.net]”替换成一个特殊字符,比如$,在根据这个字符执行Split 例如下面我要根据[111cn.net]分割的 ...
- iOS 拷贝、剪切和粘贴理论基础(转)
简介 在iPhone OS 3.0之后,用户可以在一个应用程序上拷贝文本.图像.或其它数据,然后粘贴到当前或其它应用程序的不同位置上.比如,您可以从某个电子邮件中拷贝一个地址,然后粘贴到Contact ...
- blazeDS集成spring的remote访问
欢迎交流转载,请注明出处:http://www.cnblogs.com/shizhongtao/p/3490037.html 上一篇我只是简单实用blazeds创建了一个实例,大多数开发中,都是结合 ...