私は Android をかなりやりましたが、Java 8 は初めてです。 BehaviourSubject< Map< String,String>> を作成しました。
私はそれにオブザーバブルを置きました。プレゼンター クラスから BehaviourSbuject をオブザーバブルとして設定し、onClick が行われるとすぐに onNext が同じ呼び出しを行います。しかし、rx.exceptions.OnErrorNotImplementedException をスローしています。
このhttp://reactivex.io/RxJava/javadoc/index.html?rx/exceptions/OnErrorNotImplementedException.htmlを参照したため、このエラーがスローされる理由がわかりませんが、これによると、 onNext 呼び出しでのみ作成されますまだこのエラーが発生しています。
MainScreenView は、MainScreenFragment によって実装されるインターフェイスです。
プレゼンタークラス
public class MainScreenPresenter {
public MainScreenPresenter(MainScreenView view, MainScreenModel model) {
Log.i("MainScreenPresenter", "default constructor");
view.addPlace().subscribe(place -> model.place(place));
}
}
MainScreenFragment クラス
public class MainScreenFragment extends Fragment implements MainScreenView, View.OnClickListener {
ArrayList<Place> places;
View mainScreenRootFragment;
Button addPlace;
TextView venueDate;
Place newPlace;
BehaviorSubject<Map<String, String>> placeAdded = BehaviorSubject.create();
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
mainScreenRootFragment = inflater.inflate(R.layout.main_screen_fragment, container);
Log.i("MainScreenFragment", "onCreateView");
setRetainInstance(true);
return mainScreenRootFragment;
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Log.i("MainScreenFragment", "onViewCreated");
initializeViews(view);
setEventsForViews();
}
private void setEventsForViews() {
addPlace.setOnClickListener(this);
}
private void initializeViews(View view) {
addPlace = (Button) view.findViewById(R.id.add_place);
venueDate = (TextView) view.findViewById(R.id.venue_date);
places = new ArrayList<>();
}
@Override
public Observable<Map<String, String>> addPlace() {
Log.i("MainScreenFragment", "addPlace");
return placeAdded.asObservable();
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.add_place) {
Log.i("MainScreenFragment", "add_place button clicked");
placeData();
Log.i("MainScreenFragment", "after onNext()");
} else if (v.getId() == R.id.rv) {
}
}
private void placeData() {
Log.i("MainScreenFragment", "data is mapping in placeData()");
Map<String, String> map = new HashMap<>();
map.put("placeName", "Lonavala");
map.put("placeDate", "20/5/2015");
placeAdded.onNext(map);
}
}
エラー
07-10 10:14:25.414 2754-2754/com.example.vikky.hisab W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41703d58)
07-10 10:14:25.424 2754-2754/com.example.vikky.hisab E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.vikky.hisab, PID: 2754
rx.exceptions.OnErrorNotImplementedException
at rx.Observable$31.onError(Observable.java:7204)
at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:127)
at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:96)
at rx.observers.SafeSubscriber.onNext(SafeSubscriber.java:111)
at rx.internal.operators.NotificationLite.accept(NotificationLite.java:150)
at rx.subjects.SubjectSubscriptionManager$SubjectObserver.emitNext(SubjectSubscriptionManager.java:254)
at rx.subjects.BehaviorSubject.onNext(BehaviorSubject.java:166)
at com.example.vikky.hisab.MainScreenFragment.placeData(MainScreenFragment.java:115)
at com.example.vikky.hisab.MainScreenFragment.onClick(MainScreenFragment.java:100)
at android.view.View.performClick(View.java:4444)
at android.view.View$PerformClick.run(View.java:18440)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5050)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:806)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.vikky.hisab.MainScreenPresenter.lambda$new$5(MainScreenPresenter.java:11)
at com.example.vikky.hisab.MainScreenPresenter.access$lambda$0(MainScreenPresenter.java)
at com.example.vikky.hisab.MainScreenPresenter$$Lambda$1.call(Unknown Source)
at rx.Observable$31.onNext(Observable.java:7209)
at rx.observers.SafeSubscriber.onNext(SafeSubscriber.java:104)
前もって感謝します