1
當我禁用proguard,它正常工作,但是當我用於proguard它會拋出一個異常java.lang.IllegalStateException:在Scheduler.Worker線程上引發致命異常。使用proguard與retrofit2和rxjava時出現錯誤
這是我的代碼
private fun getData(email : String) {
mSubscriptions!!.add(NetworkUtil.retrofit.getProfile(email)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe({ this.handleResponse(it) }, { this.handleError(it) }))
}
private fun handleResponse(user: List<User>) {
System.out.println(user.get(0).email)
}
private fun handleError(error: Throwable) {
if (error is HttpException) {
val gson = GsonBuilder().create()
try {
val errorBody = error.response().errorBody()!!.string()
val response = gson.fromJson<Response>(errorBody, Response::class.java)
showSnackBarMessage(response.message)
} catch (e: IOException) {
e.printStackTrace()
}
} else {
showSnackBarMessage("Network Error !")
}
}
這是例外
FATAL EXCEPTION: main
Process: sega.com.myapplication, PID: 7784
java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread.
at rx.android.schedulers.LooperScheduler$ScheduledAction.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: rx.a.e: Error occurred when trying to propagate error to Observer.onError
at rx.d.a.a(Unknown Source)
at rx.d.a.onError(Unknown Source)
at rx.c.a.g$a.onError(Unknown Source)
at rx.c.a.f$a.a(Unknown Source)
at rx.c.a.f$a.a(Unknown Source)
at rx.android.schedulers.LooperScheduler$ScheduledAction.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: rx.a.a: 2 exceptions occurred.
at rx.d.a.a(Unknown Source)
at rx.d.a.onError(Unknown Source)
at rx.c.a.g$a.onError(Unknown Source)
at rx.c.a.f$a.a(Unknown Source)
at rx.c.a.f$a.a(Unknown Source)
at rx.android.schedulers.LooperScheduler$ScheduledAction.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: rx.a.a$a: Chain of Causes for CompositeException In Order Received =>
at android.util.Log.printlns(Log.java:415)
at com.android.internal.os.RuntimeInit.Clog_e(RuntimeInit.java:61)
at com.android.internal.os.RuntimeInit.-wrap0(RuntimeInit.java)
at com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:86)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1068)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1063)
at rx.android.schedulers.LooperScheduler$ScheduledAction.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: retrofit2.adapter.rxjava.HttpException: HTTP 400 Bad Request
at retrofit2.adapter.rxjava.BodyOnSubscribe$BodySubscriber.onNext(Unknown Source)
at retrofit2.adapter.rxjava.BodyOnSubscribe$BodySubscriber.onNext(Unknown Source)
at retrofit2.adapter.rxjava.CallArbiter.deliverResponse(Unknown Source)
at retrofit2.adapter.rxjava.CallArbiter.emitResponse(Unknown Source)
at retrofit2.adapter.rxjava.CallExecuteOnSubscribe.call(Unknown Source)
at retrofit2.adapter.rxjava.CallExecuteOnSubscribe.call(Unknown Source)
at retrofit2.adapter.rxjava.BodyOnSubscribe.call(Unknown Source)
at retrofit2.adapter.rxjava.BodyOnSubscribe.call(Unknown Source)
at rx.d.a(Unknown Source)
at rx.c.a.g$a.a(Unknown Source)
at rx.c.c.a$b$1.a(Unknown Source)
at rx.c.c.f.run(Unknown Source)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
Caused by: b.a
at sega.com.myapplication.activity.LoginActivity.b(Unknown Source)
at sega.com.myapplication.activity.LoginActivity.a(Unknown Source)
at sega.com.myapplication.activity.LoginActivity.a(Unknown Source)
at sega.com.myapplication.activity.LoginActivity$e.a(Unknown Source)
at sega.com.myapplication.activity.LoginActivity$e.call(Unknown Source)
at rx.c.e.a.onError(Unknown Source)
at rx.d.a.a(Unknown Source)
at rx.d.a.onError(Unknown Source)
at rx.c.a.g$a.onError(Unknown Source)
at rx.c.a.f$a.a(Unknown Source)
at rx.c.a.f$a.a(Unknown Source)
at rx.android.schedulers.LooperScheduler$ScheduledAction.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
我使用編譯過測試 'com.artemzin.rxjava:proguard的規則:1.3.0.0',但它仍然不工作
它仍然錯誤:(我不知道爲什麼我得到錯誤:retrofit2.adapter.rxjava.HttpException:當我使用proguard HTTP 400錯誤請求 –
你排除了你的模型和請求從proguard? –
哦,夥計!我忘了 。非常感謝你 。當我度過4小時時,你是我的救助者,但我不知道爲什麼我有這個錯誤:) –