我的Android App有IllegalStateException,怎么解决?

时间:2016-01-05 08:51:39

标签: android

此错误我的应用崩溃报告服务已报告了许多实例:

java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. 
Make sure the content of your adapter is not modified from a background thread, 
but only from the UI thread. [in ListView(16908298, 
class com.handmark.pulltorefresh.library.PullToRefreshListView$InternalListViewSDK9) with Adapter(class android.widget.HeaderViewListAdapter)]
                                                 at android.widget.ListView.layoutChildren(ListView.java:1555)
                                                 at android.widget.ListView.setSelectionInt(ListView.java:2044)
                                                 at android.widget.AbsListView.resurrectSelection(AbsListView.java:5322)
                                                 at android.widget.AbsListView.onWindowFocusChanged(AbsListView.java:2736)
                                                 at android.view.View.dispatchWindowFocusChanged(View.java:7578)
                                                 at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:962)
                                                 at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:966)
                                                 at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:966)
                                                 at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:966)
                                                 at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:966)
                                                 at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:966)
                                                 at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:966)
                                                 at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:966)
                                                 at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:966)
                                                 at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:966)
                                                 at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:966)
                                                 at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:966)
                                                 at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:966)
                                                 at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:966)
                                                 at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:966)
                                                 at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:966)
                                                 at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3123)
                                                 at android.os.Handler.dispatchMessage(Handler.java:99)
                                                 at android.os.Looper.loop(Looper.java:137)
                                                 at android.app.ActivityThread.main(ActivityThread.java:5166)
                                                 at java.lang.reflect.Method.invokeNative(Native Method)
                                                 at java.lang.reflect.Method.invoke(Method.java:525)
                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:745)
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:561)
                                                 at dalvik.system.NativeStart.main(Native Method)

我不知道造成这种情况的原因,我想我会打开一个单独的更集中的问题

这是我的代码。

private void getOrdersList() {
    LogUtil.e(TAG, "getOrdersList");
    if (mOrderList == null || mOrderList.isEmpty()) {
        showLoadingPage();
    }
    LogUtil.e(TAG, "getOrdersList not null");
    LogUtil.e(TAG, "getOrdersList Thread name-->" + Thread.currentThread().getName());
    int schoolId = mPrefs.getInt(Constants.KEY.PREF_USER_SCHOOL_ID, -1);
    mServer.getOrderList(schoolId, mFilterStatusIds, mFilterName, mPageSize, mCurIndex, new ServerService.ResultListener() {

        @Override
        public void onSuccess(Object pData) {
            LogUtil.e(TAG, "getOrdersList onSuccess -->" + mOrdersLv.getState());
            mOrdersLv.onRefreshComplete();
            Log.d(TAG, "get order List successs");
            mCount = (int) (((Object[]) pData)[0]);
            if (mCurIndex == 0) {
                //第一页
                mOrderList = (ArrayList<CustomerInfo>) (((Object[]) pData)[1]);
            } else {
                if (mOrderList == null) {
                    mOrderList = new ArrayList<>();
                }
                mOrderList.addAll((ArrayList<CustomerInfo>) (((Object[]) pData)[1]));
            }
            if (Looper.myLooper() == Looper.getMainLooper()) {
                //判断是否在主线程
                LogUtil.e(TAG, "onSuccess looper in main thread");
                mOrdersLv.requestLayout();
                mAdapter.notifyDataSetChanged();
            } else {
                LogUtil.e(TAG, "onSuccess looper not in main thread");
            }
            LogUtil.d(TAG, "onSuccess Thread name-->" + Thread.currentThread().getName());
            dismissLoadingPage(true);
            mActivity.dismissProgressDialog();
            //指示下一页
            mCurIndex++;

            if (mFilterStatusIds != null && !mFilterStatusIds.isEmpty()) {
                mActionResultTv.setText("筛选结果(" + mCount + ")");
            }

        }

        @Override
        public void onFailure(int pCode, String pMsg) {
            LogUtil.e(TAG, "getOrdersList onFailure -->" + mOrdersLv.getState());
            mOrdersLv.onRefreshComplete();
            if (mOrderList != null && !mOrderList.isEmpty()) {
                dismissLoadingPage(true);
            } else {
                dismissLoadingPage("暂无学员下单");
                mCount = 0;
            }
            mActivity.dismissProgressDialog();
            if (mCurIndex == 0 && (mFilterStatusIds != null && !mFilterStatusIds.isEmpty())) {
                if (mOrderList != null) {
                    mOrderList.clear();
                }
                mCount = 0;
                if (Looper.myLooper() == Looper.getMainLooper()) {
                    //判断是否在主线程
                    LogUtil.e(TAG, "onFailure looper 在主线程");
                    mOrdersLv.requestLayout();
                    mAdapter.notifyDataSetChanged();
                } else {
                    LogUtil.e(TAG, "onFailure looper 不在主线程");
                }

                dismissLoadingPage(true);
                mActionResultTv.setText("筛选结果(" + mCount + ")");
            }


            if (pCode == Constants.STATUS_CODE.NETWORK_ERROR) {
                CustomToast.show(mActivity, R.string.network_error, Toast.LENGTH_SHORT);
            } else {
                CustomToast.show(mActivity, pMsg, R.mipmap.ic_alert, Toast.LENGTH_SHORT);
                if (mOrderList != null && mCurIndex == 0) {
                    //清空原有订单信息
                    mOrderList.clear();
                }
            }
        }
    });
}

所以。我已经把它定位在这里是一个问题,但我不知道为什么它会成为一个问题。

0 个答案:

没有答案