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 ...
随机推荐
- android-partition分析
转载请注明来源:cuixiaolei的技术博客 这里讲下android的分区.具体的使用在另一片文章中介绍,这里只是把它拿出来介绍. android的存储分为两种 一种叫做RAM,如emmc标准的dd ...
- 实现Square类,让其继承自Rectangle类,并在Square类增添新属性和方法,在2的基础上,在Square类中重写Rectangle类中的初始化和打印方法
实现Square类,让其继承自Rectangle类,并在Square类增添新属性和方法,在2的基础上,在Square类中重写Rectangle类中的初始化和打印方法 #import <Found ...
- php.ini详解
[PHP] ; PHP还是一个不断发展的工具,其功能还在不断地删减 ; 而php.ini的设置更改可以反映出相当的变化, ; 在使用新的PHP版本前,研究一下php.ini会有好处的 ;;;;;;;; ...
- Mirco2440核心板设计思考
1.核心板架构 注意的是:此处的RAM和ROM都是外置的 硬件框架 S3C2440+ SDRAM + NAND Flash + NOR Flash 也就是 CPU + RAM + ROM 2.S3C2 ...
- Android实现贪吃蛇游戏
[绥江一百]http://www.sj100.net 欢迎,进入绥江一百感谢点击[我的小网站,请大家多 ...
- response小结(三)—输出随机图片(验证码功能实现)
本文是一个很简单的向网页上输出验证码的实现喲!通过注释解释清楚了每一步! Myeclipse下的Package Explorer显示文件结构如下: ResponseDemo.java实现了输出随机图片 ...
- 关于MySql entity framework 6 执行like查询问题解决方案
原文:关于MySql entity framework 6 执行like查询问题解决方案 本人不善于言辞,直接开门见山 环境:EF6.0.0.0+MySQL Server5.6+MySqlConnec ...
- UIPickerView常见属性、常见方法(包括代理方法和数据源方法)的一些说明
一.UIPickerView 1.UIPickerView的常见属性 // 数据源(用来告诉UIPickerView有多少列多少行) @property(nonatomic,assign) id< ...
- (转)Tomcat内存设置
Java内存溢出详解 一.常见的Java内存溢出有以下三种: 1. java.lang.OutOfMemoryError: Java heap space ----JVM Heap(堆)溢出 JVM在 ...
- (转)使用CruiseControl+SVN+ANT实现持续集成之二
1. 环境搭建 1.1. 下载及目录介绍 从官方站点http://cruisecontrol.sourceforge.net/download.html下载一份最新的 CC 压缩包,最新的版本号为2. ...