Threading - Can't create handler inside thread that has not called Looper.prepare()

懵懂的女人 提交于 2019-12-02 16:19:31

问题


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.

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)

回答1:


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.



来源:https://stackoverflow.com/questions/18467470/threading-cant-create-handler-inside-thread-that-has-not-called-looper-prepar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!