When trying to execute and run the following code:

VKBatchRequest vkBatchRequest = new VKBatchRequest(vkRequestsArray); vkBatchRequest.executeWithListener(new VKBatchRequest.VKBatchRequestListener() { @Override public void onComplete(VKResponse[] responses) { super.onComplete(responses); .... } @Override public void onError(VKError error) { super.onError(error); ... } }); 

An error occurs:

 FATAL EXCEPTION: RxComputationScheduler-1 Process: com.dugin_rostislav.vkmessagesforwarder_forwarder_service, PID: 21180 java.lang.IllegalStateException: Exception thrown on Scheduler.Worker thread. Add `onError` handling. at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:60) 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:818) Caused by: rx.exceptions.OnErrorNotImplementedException: Attempt to read from field 'android.os.MessageQueue android.os.Looper.mQueue' on a null object reference at rx.internal.util.InternalObservableUtils$ErrorNotImplementedAction.call(InternalObservableUtils.java:374) at rx.internal.util.InternalObservableUtils$ErrorNotImplementedAction.call(InternalObservableUtils.java:371) at rx.internal.util.ActionSubscriber.onError(ActionSubscriber.java:44) at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:157) at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:120) at rx.exceptions.Exceptions.throwOrReport(Exceptions.java:204) at rx.observers.SafeSubscriber.onNext(SafeSubscriber.java:144) at rx.internal.operators.OperatorDelay$1$3.call(OperatorDelay.java:88) at rx.internal.schedulers.EventLoopsScheduler$EventLoopWorker$2.call(EventLoopsScheduler.java:186) 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:818) Caused by: java.lang.NullPointerException: Attempt to read from field 'android.os.MessageQueue android.os.Looper.mQueue' on a null object reference at android.os.Handler.<init>(Handler.java:238) at android.os.Handler.<init>(Handler.java:146) at com.vk.sdk.api.VKBatchRequest.executeWithListener(VKBatchRequest.java:63) at com.dugin_rostislav.vkmessagesforwarder.VKBatchRequestsCreater.sendRequestInCycle(VKBatchRequestsCreater.java:75) at com.dugin_rostislav.vkmessagesforwarder.VKBatchRequestsCreater.access$100(VKBatchRequestsCreater.java:14) at com.dugin_rostislav.vkmessagesforwarder.VKBatchRequestsCreater$2.call(VKBatchRequestsCreater.java:109) at com.dugin_rostislav.vkmessagesforwarder.VKBatchRequestsCreater$2.call(VKBatchRequestsCreater.java:106) at rx.internal.util.ActionSubscriber.onNext(ActionSubscriber.java:39) at rx.observers.SafeSubscriber.onNext(SafeSubscriber.java:139) at rx.internal.operators.OperatorDelay$1$3.call(OperatorDelay.java:88) at rx.internal.schedulers.EventLoopsScheduler$EventLoopWorker$2.call(EventLoopsScheduler.java:186) 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:818) 

In the class VKBatchRequest :

 public class VKBatchRequest extends VKObject { private final VKRequest[] mRequests; private final VKResponse[] mResponses; private final VKRequest.VKRequestListener[] mOriginalListeners; private boolean mCanceled = false; /** * Specify listener for current request */ public VKBatchRequestListener requestListener; public VKBatchRequest(VKRequest... requests) { mRequests = requests; mResponses = new VKResponse[mRequests.length]; mOriginalListeners = new VKRequest.VKRequestListener[mRequests.length]; for (int i = 0; i < mRequests.length; i++) { mOriginalListeners[i] = mRequests[i].requestListener; } } /** * Start new batch execution. At this moment a batch simply sends all requests with interval * @param listener {@link com.vk.sdk.api.VKBatchRequest.VKBatchRequestListener} */ public void executeWithListener(VKBatchRequestListener listener) { if (mRequests == null) { provideError(new VKError(VKError.VK_REQUEST_NOT_PREPARED)); return; } this.requestListener = listener; /*ТУТ*/ Handler intervalHandler = new Handler(Looper.myLooper()); int nextInterval = 0; for (final VKRequest request : mRequests) { intervalHandler.postDelayed(new Runnable() { @Override public void run() { final VKRequest.VKRequestListener originalListener = request.requestListener; request.setRequestListener(new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { provideResponse(response); } @Override public void onError(VKError error) { provideError(error); } @Override public void onProgress(VKRequest.VKProgressType progressType, long bytesLoaded, long bytesTotal) { if (originalListener != null) { originalListener.onProgress(progressType, bytesLoaded, bytesTotal); } } }); VKHttpClient.enqueueOperation(request.getOperation()); } }, nextInterval); nextInterval += 1000 / 3; } } /** * Cancel current batch request */ public void cancel() { if (mCanceled) return; mCanceled = true; for (VKRequest request : mRequests) request.cancel(); } protected void provideResponse(VKResponse response) { mResponses[indexOfRequest(response.request)] = response; for (VKResponse resp : mResponses) { if (resp == null) return; } for (int i = 0; i < mRequests.length; i++) { VKRequest.VKRequestListener l = mOriginalListeners[i]; if (l != null) { l.onComplete(mResponses[i]); } } if (requestListener != null) { requestListener.onComplete(mResponses); } } private int indexOfRequest(VKRequest request) { for (int i = 0; i < mRequests.length; i++) if (mRequests[i].equals(request)) return i; return -1; } protected void provideError(VKError error) { if (mCanceled) return; for (int i = 0; i < mRequests.length; i++) { VKRequest.VKRequestListener l = mOriginalListeners[i]; if (l != null) { l.onError(error); } } if (requestListener != null) requestListener.onError(error); cancel(); } /** * Extend listeners for requests from that class */ public static abstract class VKBatchRequestListener { /** * Called if there were no HTTP or API errors, returns execution result. * * @param responses responses from VKRequests in passing order of construction */ public void onComplete(VKResponse[] responses) { } /** * Called immediately if there was API error, or after <b>attempts</b> tries if there was an HTTP error * * @param error error for VKRequest */ public void onError(VKError error) { } } } 

On the line Handler intervalHandler = new Handler(Looper.myLooper()); , of the executeWithListener() method, an error pops up.


What is this error and how to fix it?


UPD_0: Two methods in which this code is executed (the second method restarts the first):

 private static void sendRequestInCycle() { if (requests.size() == 0) { restartMethod(); return; } final ArrayList<Request> requestsCopy = new ArrayList<>(); requestsCopy.addAll(requests); ArrayList<VKRequest> vkRequests = new ArrayList<>(); for (int i = 0; i < requestsCopy.size(); i++) { vkRequests.add(requestsCopy.get(i).getRequest()); } VKRequest[] vkRequestsArray = vkRequests.toArray(new VKRequest[vkRequests.size()]); VKBatchRequest vkBatchRequest = new VKBatchRequest(vkRequestsArray); vkBatchRequest.executeWithListener(new VKBatchRequest.VKBatchRequestListener() { @Override public void onComplete(VKResponse[] responses) { super.onComplete(responses); for (int i = 0; i < responses.length; i++) { requestsCopy.get(i).getResponseListener().onComplete(responses[i]); } requests.removeAll(requestsCopy); } @Override public void onError(VKError error) { super.onError(error); for (int i = 0; i < requestsCopy.size(); i++) { requestsCopy.get(i).getResponseListener().onError(error); } requests.removeAll(requestsCopy); } }); restartMethod(); } private static void restartMethod() { Observable.just(true) .delay(REQUEST_PERIODICITY, TimeUnit.SECONDS) .subscribe(new Action1<Boolean>() { @Override public void call(Boolean aBoolean) { sendRequestInCycle(); } }); } 
  • And if you call Looper.prepare() line above? .. - Yuriy SPb
  • Show along with the use of rxandroid to execute this code. - zRrr
  • @YuriySPb, did not help (although what we hoped for .. :)). - user189127
  • @zRrr, laid out. - user189127
  • @zRrr, as I understand it, there are no ideas? : \ - user189127

0