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 ...
随机推荐
- SpringMVC中使用Jcaptcha实现校验码验证
SpringMVC中使用Jcaptcha实现校验码验证:http://www.tuicool.com/articles/rMzAFj 本文将使用Jcaptcha实现校验码验证,并演示在Spring/S ...
- Android 自学之滚动视图ScrollView
滚动视图ScrollView由FarmeLayout派生而出,他就是一个用于为普通组件添加垂直滚动条的组件:ScrollView里面最多包含一个组件,而ScrollView的作用就是为该组件添加一个垂 ...
- #pragma CODE_SEG __NEAR_SEG NON_BANKED/#pragma CODE_SEG DEFAULT
在写到SCI 中断发送,中断接收程序的时候,在程序中会出现#pragma CODE_SEG __NEAR_SEG NON_BANKED/#pragma CODE_SEG DEFAULT,这两句话在程序 ...
- hdu1560 搜索
从原串的最大长度开始枚举,当某个长度的值能保存所有串时,即成功.对每个长度进行深搜,每次取某个串的第一个. #include<iostream> #include<cstdio> ...
- nginx实现域名重定向
一般网站默认的访问端口为80,当多个域名指向同一个服务器IP时,可以nginx进行重定向,分别指向不同的目的地址或其他主机. 在nginx目录下的conf/vhost子目录下建两个conf文件,hos ...
- bootstrap学习起步篇:初识bootstrap之html5语法构建hello篇(一)
目前选择使用bootstrap作为前端页面模板,是件很省心的事情.官网上给出的实例和教程也很多.在实际使用过程中,我们也许还要借助文档去了解它的元素和样式.但也不能减少我们使用他的兴趣. 我准备将其整 ...
- MYfirst
终于有了自己的博客了,啊哈哈!
- T-SQL 使用链接库向mysql导数据遇到的奇葩事件一
mysql表结构有 主键 非自增 text longtext类型字段多个 步骤 1.在T-SQL 临时表中处理好所有需要的字段 2.执行openquery语句 字段顺序完全按照mysql字段顺序插入 ...
- Setup Project 安装项目
从vs2012起,微软已经不支持setup project了.以此纪念一下setup project. 在新建Setup Project 增加安装内容,通常是直接Oupput一个项目,或者直接 ...
- Cocos2d-x实例:单点触摸事件
addChild(boxC,30, kBoxC_Tag); ...