JSON 배열을 다운로드하고 추가 기능을 사용하여 POJO에 매핑합니다. 성공적으로 다운로드했지만 rxJava를 사용하여 도메인 개체를 API에서 매핑하는 데 문제가 있습니다.RXJava : 치명적인 예외 매핑
public class WeatherPresenterImpl extends BasePresenter implements WeatherPresenter {
private final NetworkStateUtil networkStateUtil;
private WeakReference<WeatherListView> viewWeakReference;
private final WeatherApi weatherApi ;
private final WeatherDataMapper weatherDataMapper;
private final Scheduler observeScheduler;
private final Scheduler subscribeScheduler;
public WeatherPresenterImpl(final NetworkStateUtil networkStateUtil, final WeatherApi weatherApi, final
WeatherDataMapper weatherDataMapper, final Scheduler subscribeScheduler, final Scheduler observeScheduler) {
this.networkStateUtil = networkStateUtil;
this.weatherApi = weatherApi;
this.weatherDataMapper = weatherDataMapper;
this.observeScheduler = observeScheduler;
this.subscribeScheduler = subscribeScheduler;
}
@Override
public void activate(final WeatherListView viewWeakReference) {
this.viewWeakReference = new WeakReference<>(viewWeakReference);
}
@Override
public void requestWeatherData(String city, String apiKey) {
if (networkStateUtil.isConnected()) {
addSubscription(weatherApi.getWeather(city, WeatherApi.APIKEY)
.map(weatherDataMapper::map)
.subscribeOn(subscribeScheduler)
.observeOn(observeScheduler)
.subscribe(this::onRequestCityDataOnNext, this::onRequestCityDataError));
} else {
ifViewNotNull(WeatherListView::showNoConnectionMessage);
getDataFromDatabase();
}
}
@Override
public void requestWeatherData() {
Log.e("success","success");
}
private void onRequestCityDataError(final Throwable throwable) {
Log.e("fail",throwable.getMessage());
}
private void onRequestCityDataOnNext(final List<WeatherData> weatherDatas) {
ifViewNotNull((weatherListView) -> {
weatherListView.setWeatherData(weatherDatas);
});
}
private void ifViewNotNull(final Action1<WeatherListView> func) {
final WeatherListView weatherListView = viewWeakReference.get();
if (weatherListView != null) {
func.call(weatherListView);
}
}
이 내 매퍼 클래스입니다 :
이
내 발표자public final class WeatherDataMapper {
public final List<WeatherData> map(final WeatherDataApi listWeatherDataApi) {
List<WeatherData> weatherDataModelList = Collections.emptyList();
final int numberOfDays = 3;
for (int i = 0; i < numberOfDays; i++) {
String tempMin = String.valueOf(KelvinConverterUtil.convertKelvinToCelsius(listWeatherDataApi.list.get(i).temp.min));
String tempMax = String.valueOf(KelvinConverterUtil.convertKelvinToCelsius(listWeatherDataApi.list.get(i).temp.max));
String cityName = listWeatherDataApi.city.name;
String description = listWeatherDataApi.list.get(i).weather.get(0).description;
String humidity = String.valueOf(listWeatherDataApi.list.get(i).humidity);
String pressure = String.valueOf(listWeatherDataApi.list.get(i).pressure);
String icon = String.valueOf(listWeatherDataApi.list.get(i).weather.get(0).icon);
weatherDataModelList.add(i, new WeatherData(tempMin, tempMax, cityName, description, humidity, pressure, icon));
}
return weatherDataModelList;
}
}
그리고 나는 그것을 실행할 때이 내가 얻을 예외입니다 :
10-18 17:42:48.700 14461- 14606/package.com.openweatherappE/AndroidRuntime:FATAL EXCEPTION: RxIoScheduler-2
Process: package.com.openweatherapp, PID: 14461
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:423)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: rx.exceptions.OnErrorFailedException: Error occurred when trying to propagate error to Observer.onError
at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:192)
at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:120)
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.checkTerminated(OperatorObserveOn.java:276)
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.call(OperatorObserveOn.java:219)
at rx.internal.schedulers.CachedThreadScheduler$EventLoopWorker$1.call(CachedThreadScheduler.java:220)
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: rx.exceptions.CompositeException: 2 exceptions occurred.
at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:192)
at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:120)
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.checkTerminated(OperatorObserveOn.java:276)
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.call(OperatorObserveOn.java:219)
at rx.internal.schedulers.CachedThreadScheduler$EventLoopWorker$1.call(CachedThreadScheduler.java:220)
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: rx.exceptions.CompositeException$CompositeExceptionCausalChain: Chain of Causes for CompositeException In Order Received =>
at android.util.Log.getStackTraceString(Log.java:338)
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:693)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:66)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.UnsupportedOperationException
at java.util.AbstractList.add(AbstractList.java:404)
at package.com.openweatherapp.model.WeatherDataMapper.map(WeatherDataMapper.java:27)
at package.com.openweatherapp.presenter.WeatherPresenterImpl$$Lambda$1.call(Unknown Source)
at rx.internal.operators.OperatorMap$MapSubscriber.onNext(OperatorMap.java:66)
at retrofit.RxSupport$2.run(RxSupport.java:56)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at retrofit.Platform$Android$2$1.run(Platform.java:142)
at java.lang.Thread.run(Thread.java:818)
Caused by: rx.exceptions.OnErrorThrowable$OnNextValue: OnError while emitting onNext value: package.com.openweatherapp.data.pojo.WeatherDataApi.class
at rx.internal.operators.OperatorMap$MapSubscriber.onNext(OperatorMap.java:70)
at retrofit.RxSupport$2.run(RxSupport.java:56)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at retrofit.Platform$Android$2$1.run(Platform.java:142)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.NullPointerException: println needs a message
at android.util.Log.println_native(Native Method)
at android.util.Log.e(Log.java:232)
at package.com.openweatherapp.presenter.WeatherPresenterImpl.onRequestCityDataError(WeatherPresenterImpl.java:61)
at package.com.openweatherapp.presenter.WeatherPresenterImpl.access$lambda$1(WeatherPresenterImpl.java:0)
at package.com.openweatherapp.presenter.WeatherPresenterImpl$$Lambda$3.call(Unknown Source)
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.internal.operators.OperatorObserveOn$ObserveOnSubscriber.checkTerminated(OperatorObserveOn.java:276)
at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.call(OperatorObserveOn.java:219)
at rx.internal.schedulers.CachedThreadScheduler$EventLoopWorker$1.call(CachedThreadScheduler.java:220)
at rx.in
10-18 17:42:48.744 14461-14610/package.com.openweatherapp I/Process: Sending signal. PID: 14461 SIG: 9
'@Override public boolean onQueryTextSubmit (최종 문자열 텍스트) { weatherPresenter.requestWeatherData (text, WeatherApi.APIKEY); false를 반환합니다. }의'searchView의 단편 기본적 . 이것은 하나의 WeatherData 객체에서 작동하지만 배열에 매핑하면 문제가 발생합니다. 그러나 3 일 동안 데이터를 표시해야하므로 배열이 필요합니다. – hyrulelink16
'@Module 공공 최종 클래스 ThreadingModule { 공공 정적 최종 문자열 OBSERVE_SCHEDULER = "스케줄러을 준수"; public static final String SUBSCRIBE_SCHEDULER = "구독 스케줄러"; @Named (OBSERVE_SCHEDULER) @Singleton @Provides 공공 최종 스케줄러 provideMainThreadScheduler() { 반환 AndroidSchedulers.mainThread(); } @Named (SUBSCRIBE_SCHEDULER) @Singleton @Provides 공공 최종 스케줄러 provideIOScheduler() { 반환 Schedulers.io(); } } ' 나는 그들을 삽입하기 위해 dagger2를 사용하고 있습니다. – hyrulelink16
'Collections.emptyList();'-> 매뉴얼을 읽으십시오. – njzk2