我正在使用一些较旧的代码,并且在运行此方法时,出现Looper.prepare()错误。我不明白这条线是什么意思,但这是非常必要的。
总体程序:我有一个AsyncTask,该方法调用从doInBackground()-调用doBindService()的方法。我已经阅读了有关此错误的许多其他问题,我想我有一个线程错误,但我无法弄清楚问题是什么。
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()
Looper.prepare()