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 ...
随机推荐
- xmlns="http://schemas.xmlsoap.org/wsdl/",这是什么意思,我只知道:xmlns:xx=....,
表示没有prefix,相当于你的xsi为空.这个很常用,后面就省得每行都要加一个前缀了. 解决方案 » "后面就省得每行都要加一个前缀了",意思是,后面的子元素如果没有名称空间前缀 ...
- ganglia监控hadoop2.0配置方法
ganglia监控hadoop2.0配置方法前提:hadoop2.0集群已安装ganglia监控工具第一步:Hadoop用户登录集群每一个节点,修改文件:vi /opt/hadoop-2.0.0-cd ...
- Web前端学习笔记2
一.开发工具sublime的常用快捷键. 1. 快捷键 功能 ctrl+shift+D 快速复制 ctrl+L 快 ...
- display:none与visible:hidden区别
if(list.style.display=='none'){ list.style.display='block'; }else{ ...
- Servlet & JSP - UrlRewriteFilter
重写 URL 的好处有很多: 静态化页面,有利于搜索引擎收录. 隐藏真实的 URL,提高安全性. 当网站的结构发生变化时,无需要求用户修改书签. UrlRewriteFilter 的简单应用 1. M ...
- Quartz Scheduler(2.2.1) - Integration with Spring
1. maven 依赖: <properties> <spring.version>3.2.3.RELEASE</spring.version> <quart ...
- Java Servlet-http协议
---恢复内容开始--- 互联网三大基石: url:定位数据 html:显示数据 http:传输数据
- html dom的加载
操作HTML DOM文档的一个难题是,你的JavaScript代码可能在DOM完全载入之前运行,这会导致你的代码产生一些问题.页面加载时浏览器内部操作的顺序大致是这样的: 1. HTML被解析. 2. ...
- SQL server经典电子书、工具和视频教程汇总
SQL server经典电子书.工具和视频教程汇总 SQL server经典电子书.工具和视频教程汇总 SQL Server是高校计算机专业的一门必修课程,同时众多企业采用SQL Server作为数据 ...
- java新手笔记28 文件
1.目录.文件 package com.yfs.javase; import java.io.File; public class FileDemo1 { /** * File 目录 文件 */ pu ...