1
I have some problems when I use rxjava2 with retrofit.The following is my code:


public void sendRequest(String url, MySubscriber<NetMessage> ss, HashMap<String, String> data) {
    Flowable<NetMessage> mObservable;
    String[] paths = url.split("/");
    mObservable = myApi.getData(paths[0], paths[1], data);
    mObservable.observeOn(AndroidSchedulers.mainThread()).
            subscribeOn(Schedulers.io())
            .subscribe(ss);
}

这是我调用函数的代码

public void sendRequestForModifyInfo(final String field, final String value) {
    MySubscriber<NetMessage> ss = new MySubscriber<NetMessage>() {
        @Override
        public void onNext(NetMessage o) {
            super.onNext(o);
            if (o != null && o.getCode() == 0) {
                JJMToast.showToast(thisActivity, "Success", Toast.LENGTH_SHORT);
            }
            switch (field) {
                case "nickname":
                    ((TextView) views.get(2)).setText(value);
                    break;
                case "description":
                    ((TextView) views.get(3)).setText(value);
                    break;
            }
        }

        @Override
        public void onError(Throwable t) {
            super.onError(t);
            JJMToast.showToast(thisActivity, "error", Toast.LENGTH_SHORT);
        }
    };
    JJMApiManager.getInstance().sendRequest(HttpData.InterfaceURL.USER_MODIFY, ss, HttpData.getUserModify(RunTimeInfo.getInstance().login_token, field, value));
}

当值的长度很短时是正确的,当我将的长度变长时,它会报错: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()

getData是一个抽象函数

4

0 回答 0