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

1.5k views Asked by At

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

There are 1 answers

2
Josh M On BEST ANSWER

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.