在调试软件的时候出现如下的错误:

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. 开发错误记录1:解决:Only the original thread that created a view hierarchy can touch its views.

    今天在项目中要使用圆角头像,导入开源 CircleImageView ,然后setImageBitmap()时 运行时就会发现,它会报一个致命性的异常:: · ERROR/AndroidRuntime ...

  2. 浅析Android中的消息机制-解决:Only the original thread that created a view hierarchy can touch its views.

    在分析Android消息机制之前,我们先来看一段代码: public class MainActivity extends Activity implements View.OnClickListen ...

  3. Android: Only the original thread that created a view hierarchy can touch its views 异常

    最近自己再写一个小项目练手,创建一个线程从网络获取数据然后显示在 recyclerView 上.写好后发现页面能够显示,但是有时候会把请求的数据显示过来,有时候不会.点开 android monito ...

  4. Only the original thread that created a view hierarchy can touch its views解决办法

    这周操作系统作业布置了一个作业,内容是做个小软件,来模拟消费者生产者问题,作业实现起来不来,因为之前写过这个算法,所以关键步骤就是在消费和生产的时候更新缓存区的UI控件就行,之后问题就来了,出现了标题 ...

  5. 错误: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 ...

  6. 子线程调用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 最顶层的 ...

  7. 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 ...

  8. 解决Only the original thread that created a view hierarchy can touch its views

    这种异常出现在子线程中处理UI操作产生的异常,将UI操作放在主线程中就OK了

  9. "Only the original thread that created a view hierarchy can touch its views.” 解决方法

    这个主要总是,开启的线程和 UI 线程(主线程)不是同一个线程.可以Runnable方式避免,如下例所示就可以解决这个问题了. public static void updateText(Activi ...

随机推荐

  1. c语言排序算法总结

    一.希尔(Shell)排序法 /* Shell 排序法 */ #include <stdio.h> void sort(int v[],int n) {      int gap,i,j, ...

  2. Syntax highlighter for CKEditor

    http://www.cnblogs.com/moozi/archive/2010/01/06/1640034.html

  3. Android 自学之列表视图ListView和ListActivity

    ListView是手机系统中使用非常广泛的一种组件,它以垂直列表的形式显示所有列表项. 创建ListView有两种方式: 直接使用ListView创建. 让Activity继承ListActivity ...

  4. CSS-Sprite-Generator丨CSS雪碧在线生成器

    http://cn.spritegen.website-performance.org/ Css Sprite Tools实现背景图片整合 http://www.onlinedown.net/soft ...

  5. saltstack实战2--远程执行之模块(Modules)

    本来转自http://www.cnblogs.com/MacoLee/p/5753640.html  版权归原作者所有 说明 salt '*' sys.list_modules #列出当前版本支持的模 ...

  6. js学习笔记—转载(闭包问题)

    ---恢复内容开始--- 闭包(closure)是Javascript语言的一个难点,也是它的特色,很多高级应用都要依靠闭包实现.     一.变量的作用域 要理解闭包,首先必须理解Javascrip ...

  7. 编译mosquitto出现的问题

    [root@localhost mosquitto-1.3]# make WITH_TLS=no set -e; for d in lib client src; do make -C ${d}; d ...

  8. jQuery性能优化(转)

    摘要:jQuery是我们经常使用的强大的JS类库,因此它的性能优化十分重要,下面就重几点来说明 原文作者:szyuxueliang    原文地址:http://www.cnblogs.com/yxl ...

  9. jQuery 自定义事件的学习笔记

    jquery中提供了两种方法可以绑定自定义事件: bind()和one()而绑定的自定义事件的触发,必须得用jquery中的trigger()方法才能触发. 我们先来看on事件  代码如下 复制代码 ...

  10. npm install --save 与 npm install --save-dev 的区别

    以npm安装msbuild为例: npm install msbuild: 会把msbuild包安装到node_modules目录中 不会修改package.json 之后运行npm install命 ...