今天编程时候遇到一个问题:

 W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x419b4c50) 
。。。。
log完全没有,,,这个时候有心杀贼,无力回天啊,,,,什么报错信息都没有。
百度各种问题解决方案,最终有一篇文章:http://blog.csdn.net/liqiangeastsun/article/details/43986605  讲了一个解决问题的方案:
以下是原文:

Android错误threadid=1: thread exiting with uncaught exception (group=0x416298c8)

在项目开发中测试时崩溃,错误如上 
该错误的意思是线程中存在没有捕获到的异常。一般情况下捕获异常使用

 try {} catch (Exception e){}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

但是在线程池中,线程池在执行任务时捕获了所有异常,这样一来线程中所有的异常都无法捕获到抛出的异常。 
即 try catch 捕获不到异常了。 
Java中有一个接口,UncaughtExceptionHandler 描述如下:

static interface Thread.UncaughtExceptionHandler
// 当 Thread 因未捕获的异常而突然终止时,调用处理程序的接口。
  • 1
  • 2
  • 1
  • 2

Thread类中的一个方法

static void
setDefaultUncaughtExceptionHandler(Thread.UncaughtExceptionHandler eh)
//设置当线程由于未捕获到异常而突然终止,并且没有为该线程定义其他处理程序时所调用的默认处理程序。
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

我们需要实现这样一个接口UncaughtExceptionHandler,然后在程序的主线程中设置处理程序。 
代码如下


import java.lang.Thread.UncaughtExceptionHandler;//implements UncaughtExceptionHandler
public class Other extends Activity implements UncaughtExceptionHandler {//必须实现接口uncaughtException
@Override
public void uncaughtException(Thread arg0, Throwable arg1) {//在此处理异常, arg1即为捕获到的异常  Log.i("AAA", "uncaughtException   " + arg1);}}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

现在还无法捕获到线程中的异常,还需要调用一个方法

Thread.setDefaultUncaughtExceptionHandler(this);
  • 1
  • 1

在OnCreate方法中调用一下即可

@Override
protected void onCreate(Bundle savedInstanceState) {//在OnCreate方法中调用下面方法,然后再使用线程,就能在uncaughtException方法中捕获到异常Thread.setDefaultUncaughtExceptionHandler(this);
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 1
  • 2
  • 3
  • 4
  • 5

完整代码如下

    //导入包import java.lang.Thread.UncaughtExceptionHandler;//implements UncaughtExceptionHandlerpublic class Other extends Activity implements UncaughtExceptionHandler       {@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.th);//在此调用下面方法,才能捕获到线程中的异常Thread.setDefaultUncaughtExceptionHandler(this);//获取创建的 Buttonbtn1 = (Button) findViewById(R.id.btn);//给btn1添加一个点击监听事件btn1.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View arg0) {//调用我自己的方法Init();}});}public void Init() {//开启线程new Handler(Looper.getMainLooper()).post(new Runnable() {   @Overridepublic void run() {//此处的 try catch 是无法捕获到异常的try {////////////////////////////////////////////需要在线程中调用的方法purchase.init(context, iapListener)purchase.init(context, iapListener);//////////////////////////////////////////} catch (Exception e) {// TODO: handle exceptionLog.i("AAA", "INIG   " + e);e.printStackTrace();}}});}//必须实现接口uncaughtException@Overridepublic void uncaughtException(Thread arg0, Throwable arg1) {//在此处理异常, arg1即为捕获到的异常Log.i("AAA", "uncaughtException   " + arg1);}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52

这样再次运行就会捕获到线程中的异常,不会导致项目直接崩溃

最终可以打印出log信息了,报错为:(Android5.0以上没这个问题,5,0以下有问题的)
java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams 
问题已经很明显了,类强转时候报的问题:
解决方案: 
android.view.ViewGroup.LayoutParams

改为:

android.widget.AbsListView.LayoutParams
这个问题到不是很关键,主要问题是找到了方法,当log不能显示异常信息时候,,,,可以帮我们打印出log信息,然后分析问题,解决问题。。。。

W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x419b4c50)相关推荐

  1. 【elasticsearch】ES启动报错 uncaught exception in thread [main]org.elasticsearch.bootstrap.Startup

    完整的错误信息是: uncaught exception in thread [main]org.elasticsearch.bootstrap.StartupException:   java.la ...

  2. 【22.05.14】native thread exiting without having called DetachCurrentThread

    native thread exiting without having called DetachCurrentThread: javaVM->AttachCurrentThread之后要在某 ...

  3. jmeter使用报错ERROR o.a.j.JMeter: Uncaught exception in thread Thread[AWT-EventQueue-0,6,main]

    最近开始自学接触jmeter,但是在跑接口的时候发现报错了(接口使用postman已经跑通过,在自查一通以后终于发现原因) 先上错误提示:我们主要先看error,可以看到ERROR o.a.j.JMe ...

  4. JMeter直连数据库报错Uncaught Exception java.lang.AbstractMethodError: com.mysql.jdbc.Connection.isValid(I)Z

    报错:Uncaught Exception java.lang.AbstractMethodError: com.mysql.jdbc.Connection.isValid(I)Z in thread ...

  5. Terminating app due to uncaught exception 'NSGenericException' 类崩溃文章收集

    返回崩溃:nested pop animation can result in corrupted navigation bar nested pop animation can re 使用Xcode ...

  6. terminating with uncaught exception of type std::bad_cast: std::bad_cast

    terminating with uncaught exception of type std::bad_cast: std::bad_cast 我这里的情况: 我有两个so A 和B,调用程序c 把 ...

  7. BB之Uncaught exception:net.rim.device.api....错误的解决之道

    最近弄了包月GPRS,于是开始捣鼓bb的Gmail功能...可是, 装了N遍的Gmail 1.5 或2.0 版本的程序后, 打开, 界面总是会出现 "Uncaught exception:n ...

  8. 使用imagick将PDF转换成图片时报Fatal error: Uncaught exception 'ImagickException' with message 'FailedToExecute

    个人博客原文地址:http://www.lampnick.com/php/720 $IM = new imagick(); $IM->setResolution(200, 200); $IM-& ...

  9. ios 常见异常之- Terminating app due to uncaught exception ‘NSInternalInconsistencyException‘, reason:

    异常全部信息: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '<S ...

最新文章

  1. 程序员效率低下的35个坏习惯
  2. python批量分析表格_Python环境下百度Ocr表格批量识别
  3. VB6 XArrayDB | Xarray ReDim 用法
  4. [POJ 1003] Hangover C++解题
  5. pfSense book之 Open***站点到站点连接示例(共享密钥)
  6. powerbi add visual diagram
  7. C++线程池原理及创建(转)
  8. 现代软件工程系列 学生读后感 梦断代码 SpringGreen
  9. PHP操作视频音频类 FFmpegPHP
  10. 如果40岁仍碌碌无为,牢记2句话,最迟也是大器晚成
  11. bzoj 3027: [Ceoi2004]Sweet(母函数+组合数)
  12. .net反编译工具reflector5.0 的介绍及使用
  13. 有将视频横屏改为竖屏的方法吗?
  14. 公司要收我的毕业证书,这合法吗?——网上答疑(17)
  15. CEOI 2020, Day 2 A,B题解 CF1403A CF1403B
  16. python批量改文件名,截取原文件名的一部分
  17. 在linux下运用mutt和msmtp发邮件
  18. 数据中心的“灾备”指的是什么?
  19. 2023年最新前端面试题
  20. SQL*Plus 系统变量之28 - LOBOF[FSET]

热门文章

  1. NPOI导出word,NPOI导出word表格,NPOI复制table表格 XWPFDocument中XWPFTable
  2. zlib 1.2.9 not found
  3. clickhouse 集群异常排查处理总结
  4. 百家号同步公众号的自媒体工具有吗?
  5. Antd给表格一个斜线分隔
  6. JavaScript 排他思想
  7. 搭配Online:腾讯吃鸡手游《PUBG Mobile》及《和平精英》(前《刺激战场》)全球收入超15亿美元!
  8. Asp.net的CheckBox控件和CheckBoxList控件
  9. 获取农历节日的公共方法
  10. MuMu模拟器 安装电脑本地apk