我在其中使用 Service 和 AsyncTask 时遇到了一点问题。我编写了一个做一些 HTTP 工作的小类,它执行一个 AsyncTask 以在后台完成所有 HTTP 工作,当它完成时,它用响应数据调用一个侦听器。
现在我需要在服务(远程服务)中使用该类,并且每次该类尝试从 AsyncTask 类创建一个对象时,它都会崩溃并在日志 cat 中显示以下消息:
05-07 10:30:01.847: E/JavaBinder(1026): *** Uncaught remote exception! (Exceptions are not yet supported across processes.)
05-07 10:30:01.847: E/JavaBinder(1026): java.lang.ExceptionInInitializerError
05-07 10:30:01.847: E/JavaBinder(1026): at com.lowlevel.umusic.VK.getById(VK.java:46)
05-07 10:30:01.847: E/JavaBinder(1026): at com.lowlevel.umusic.Song.requestUri(Song.java:109)
05-07 10:30:01.847: E/JavaBinder(1026): at com.lowlevel.umusic.PlayService$1.playSong(PlayService.java:149)
05-07 10:30:01.847: E/JavaBinder(1026): at com.lowlevel.umusic.IPlayService$Stub.onTransact(IPlayService.java:55)
05-07 10:30:01.847: E/JavaBinder(1026): at android.os.Binder.execTransact(Binder.java:320)
05-07 10:30:01.847: E/JavaBinder(1026): at dalvik.system.NativeStart.run(Native Method)
05-07 10:30:01.847: E/JavaBinder(1026): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
05-07 10:30:01.847: E/JavaBinder(1026): at android.os.Handler.<init>(Handler.java:121)
05-07 10:30:01.847: E/JavaBinder(1026): at android.os.AsyncTask$InternalHandler.<init>(AsyncTask.java:421)
05-07 10:30:01.847: E/JavaBinder(1026): at android.os.AsyncTask$InternalHandler.<init>(AsyncTask.java:421)
05-07 10:30:01.847: E/JavaBinder(1026): at android.os.AsyncTask.<clinit>(AsyncTask.java:152)
05-07 10:30:01.847: E/JavaBinder(1026): ... 6 more
05-07 10:30:01.847: W/dalvikvm(1026): threadid=8: thread exiting with uncaught exception (group=0x40015560)
05-07 10:30:01.847: E/AndroidRuntime(1026): FATAL EXCEPTION: Binder Thread #2
05-07 10:30:01.847: E/AndroidRuntime(1026): java.lang.ExceptionInInitializerError
05-07 10:30:01.847: E/AndroidRuntime(1026): at com.lowlevel.umusic.VK.getById(VK.java:46)
05-07 10:30:01.847: E/AndroidRuntime(1026): at com.lowlevel.umusic.Song.requestUri(Song.java:109)
05-07 10:30:01.847: E/AndroidRuntime(1026): at com.lowlevel.umusic.PlayService$1.playSong(PlayService.java:149)
05-07 10:30:01.847: E/AndroidRuntime(1026): at com.lowlevel.umusic.IPlayService$Stub.onTransact(IPlayService.java:55)
05-07 10:30:01.847: E/AndroidRuntime(1026): at android.os.Binder.execTransact(Binder.java:320)
05-07 10:30:01.847: E/AndroidRuntime(1026): at dalvik.system.NativeStart.run(Native Method)
05-07 10:30:01.847: E/AndroidRuntime(1026): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
05-07 10:30:01.847: E/AndroidRuntime(1026): at android.os.Handler.<init>(Handler.java:121)
05-07 10:30:01.847: E/AndroidRuntime(1026): at android.os.AsyncTask$InternalHandler.<init>(AsyncTask.java:421)
05-07 10:30:01.847: E/AndroidRuntime(1026): at android.os.AsyncTask$InternalHandler.<init>(AsyncTask.java:421)
05-07 10:30:01.847: E/AndroidRuntime(1026): at android.os.AsyncTask.<clinit>(AsyncTask.java:152)
05-07 10:30:01.847: E/AndroidRuntime(1026): ... 6 more
有什么想法,或者我必须修改我的课程以同步工作?
谢谢!