Error with retrofit 2 : java.lang.NoSuchMethodError: com.google.gson.Gson.newJsonReader, after updating gradle

963 views Asked by At

My problem appeared after I updated Android studio to the latest version with gradle version 2.2.*. I'm using dagger 2 rxjava retrofit and happen to face this problem:

E/AndroidRuntime: FATAL EXCEPTION: RxCachedThreadScheduler-1
              Process: com.appsmedia.blaan2, PID: 19224
              java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread.
                  at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:62)
                  at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
                  at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152)
                  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265)
                  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
                  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
                  at java.lang.Thread.run(Thread.java:841)
               Caused by: java.lang.NoSuchMethodError: com.google.gson.Gson.newJsonReader
                  at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:35)
                  at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:25)
                  at retrofit2.ServiceMethod.toResponse(ServiceMethod.java:116)
                  at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:211)
                  at retrofit2.OkHttpCall.execute(OkHttpCall.java:174)
                  at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$RequestArbiter.request(RxJavaCallAdapterFactory.java:171)
                  at rx.internal.operators.OperatorSubscribeOn$1$1$1.request(OperatorSubscribeOn.java:80)
                  at rx.Subscriber.setProducer(Subscriber.java:211)
                  at rx.internal.operators.OperatorSubscribeOn$1$1.setProducer(OperatorSubscribeOn.java:76)
                  at rx.Subscriber.setProducer(Subscriber.java:205)
                  at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:152)
                  at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:138)
                  at rx.Observable$2.call(Observable.java:233)
                  at rx.Observable$2.call(Observable.java:225)
                  at rx.Observable.unsafeSubscribe(Observable.java:8741)
                  at rx.internal.operators.OperatorSubscribeOn$1.call(OperatorSubscribeOn.java:94)
                  at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
                  at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422) 
                  at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
                  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:152) 
                  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:265) 
                  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
                  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
                  at java.lang.Thread.run(Thread.java:841) 
1

There are 1 answers

0
halfer On BEST ANSWER

(Posted on behalf of the OP).

Changing retrofit version to the lastest one solved my problem.