【问题标题】:APP Crash : Fatal Exception: io.reactivex.exceptions.CompositeException应用程序崩溃:致命异常:io.reactivex.exceptions.CompositeException
【发布时间】:2017-12-05 08:30:31
【问题描述】:

使用retrofit 我调用API 来获取列表,但是当没有找到数据时,我调用onErrorGetOccasion 方法并得到HttpException,为此我按照代码所示处理它。

现在我的问题有时是在onErrorGetOccasion 方法中我得到了致命的

Exception: io.reactivex.exceptions.CompositeException this error and app crash.

对此有何建议?

//Get Occasion API
private void callGetOccasionAPI(String pageIndex, boolean isDialogShown) {

    if (NetworkUtils.isConnected()) {
        if (mPageCount == 1 && isDialogShown)
            showProgressDialog(mContext);
        RetrofitAdapter.createRetroServiceWithSessionToken(mContext)
                .getOccasion(pageIndex)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(this::onSuccessGetOccasion, this::onErrorGetOccasion);
    } else {
        SnackBarUtils.defaultSnackBar(getString(R.string.error_no_internet), mRootView);
    }
}

private void onErrorGetOccasion(Throwable throwable) {
    hideProgressDialog();
    if (throwable instanceof HttpException) {
        ResponseBody body = ((HttpException) throwable).response().errorBody();
        Utils.setLog(body != null ? body.toString() : null);
        try {
            if (body != null) {
                if (body.string().contains(mContext.getString(R.string.msg_event_not_found))) {
                    if (mPageCount == 1) {
                        mTxtRecordNotFound.setVisibility(View.VISIBLE);
                        mRecyclerView.setVisibility(View.INVISIBLE);
                    }
                } else {
                    SnackBarUtils.errorSnackBar(getString(R.string.error_api), mRootView, null);
                }
            }

        } catch (IOException e) {
            e.printStackTrace();
            Crashlytics.log(e.getMessage());
        }
    }
}

【问题讨论】:

    标签: android retrofit2 reactivex


    【解决方案1】:

    CompositeException 通常在您的错误处理程序本身在处理流中抛出的错误时抛出异常时抛出。

    确保您的错误处理代码没有抛出任何异常。

    通常堆栈跟踪将在CompositeException 下方有根本原因,并以Caused by 为前缀。

    【讨论】:

    • 怎么处理?
    • 您需要查看底层异常是什么,如果它是需要修复的东西,例如 NullPointerException 或要捕获的东西,IOException,发布您的完整堆栈跟踪也会有所帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-22
    • 2021-04-23
    • 1970-01-01
    • 1970-01-01
    • 2015-07-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多