线程 - 无法在未调用 Looper.prepare() 的线程内创建处理程序 [英] Threading - Can't create handler inside thread that has not called Looper.prepare()

查看:62
本文介绍了线程 - 无法在未调用 Looper.prepare() 的线程内创建处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一些旧代码,在运行此方法时,出现 Looper.prepare() 错误.我不明白这条线是什么意思,但这是非常必要的.

I am using some older code and in running this method, I get the Looper.prepare() error. I don't understand what the line means but it is very necessary.

整体程序:我有一个 AsyncTask,它调用一个调用 doBindService()--from doInBackground()-- 的方法.我已经阅读了许多关于此错误的其他问题,我想我有一个线程错误,但我无法弄清楚问题是什么.

Overall program: I have an AsyncTask that calls a method which calls doBindService()--from doInBackground()--. I have read the numerous other questions about this error and I guess I have a threading error but I can't figure out what the issue is.

public rNOC doBindService(){

         _server = new rNOC(this);//CODE FAILING HERE
        return _server;
        }


 *** Uncaught remote exception!  (Exceptions are not yet supported across processes.)
    java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
    at android.os.Handler.<init>(Handler.java:197)
    at android.os.Handler.<init>(Handler.java:111)
    at com.servicenexus.ServiceNexus$1.<init>(ServiceNexus.java:128)
    at com.servicenexus.ServiceNexus.<init>(ServiceNexus.java:128)
    at com.servicenexus.rNOC.<init>(rNOC.java:31)
    at com.servicenexus.ServiceNexus.doBindService(ServiceNexus.java:406)
    at com.servicenexus.ServiceNexus$2.login(ServiceNexus.java:790)
    at com.servicenexus.IRemoteInterface$Stub.onTransact(IRemoteInterface.java:126)
    at android.os.Binder.execTransact(Binder.java:351)
    at dalvik.system.NativeStart.run(Native Method)

推荐答案

java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() 似乎是一个非常详细的错误信息;如果它在该特定行出错(我假设处理程序正在那里创建)并从堆栈跟踪判断,我会建议在错误发生之前调用 Looper.prepare().

java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() seems to be a pretty detailed error message; if it errors at that particular line (I'm assuming the handler is being created there) and judging from the stack trace, I would suggest calling Looper.prepare() before the error occurs.

这篇关于线程 - 无法在未调用 Looper.prepare() 的线程内创建处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆