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

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. python(3)-lambda表达式

    >>> fun = lambda a: a+1 >>> fun(1) 2 >>> fun = lambda a,b: a+b >>&g ...

  2. [改善Java代码]不要主动进行垃圾回收

    建议51: 不要主动进行垃圾回收 很久很久以前,在Java 1.1的年代里,我们经常会看到System.gc这样的调用—主动对垃圾进行回收.不过,在Java知识深入人心后,这样的代码就逐渐销声匿迹了— ...

  3. HDU 1003 - Max Sum(难度:*)

    Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum ...

  4. mysql 5.7 root password 过期

    重新修改root密码 SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass'); ALTER USER 'root'@localhost' P ...

  5. ActiveMQ(5.10.0) - hello world

    Sending a JMS message public class MyMessageProducer { ... // 创建连接工厂实例 ConnectionFactory connFactory ...

  6. HTTP相关知识 --转载

    转载之,言简意赅

  7. Android之屏幕测试

    MainActivity: package com.example.touchscreentest; import android.os.Bundle; import android.R.layout ...

  8. Eclipse Code Templates设置

    从工作开始,经历了几个项目的开发,现在的项目一般都是一个团队共同开发,而每个人都有自己的编码习惯,为了统一格式,项目组在项目开发之前都会制定一系列的规范.俗话说约定优于配置,但是在执行过程中往往发现效 ...

  9. java进阶一之jdk8新特性

    1.官方发布的jdk8新特性 2.51CTO相关专题

  10. Poj 2840 Big Clock

    1.Link: http://poj.org/problem?id=2840 2.Content: Big Clock Time Limit: 1000MS   Memory Limit: 13107 ...