[英]Threading - Can't create handler inside thread that has not called Looper.prepare()
I am using some older code and in running this method, I get the Looper.prepare() error. 我正在使用一些较旧的代码,并且在运行此方法时,出现Looper.prepare()错误。 I don't understand what the line means but it is very necessary. 我不明白这条线是什么意思,但这是非常必要的。
Overall program: I have an AsyncTask that calls a method which calls doBindService()--from doInBackground()--. 总体程序:我有一个AsyncTask,该方法调用从doInBackground()-调用doBindService()的方法。 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()
seems to be a pretty detailed error message; java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
似乎是一条非常详细的错误消息; 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()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.