-2

谁能帮我解决这个奇怪的错误?当我收到错误时,我标记了该行。谢谢

         /************************************************
         *      setItemsAsReadTask
         ************************************************/

        private class SetItemsAsReadTask extends AsyncTask<ArrayList<FeedItem>, Void, Void> {

            @Override
              protected void onPreExecute() {
                //AGGIORNO LISTVIEW SUBSCRIPTIONS

                }


            @Override
            protected Void doInBackground(ArrayList<FeedItem> ... articoli) {
                if(this.isCancelled()==false){
                    if(articoli.length!=0){
                ArrayList<FeedItem> segnaComeLetti = articoli[0];
                reader.setMultipleNewsAsRead(segnaComeLetti);
                    }
                }
                return null;

            }

            @Override
            protected void onPostExecute(Void v) {
                //TODO TRUE O FALSE
                if(this.isCancelled()==false){
                    Log.d(TAG, "chiedo aggiornamento updateUI");
                    mCallbacks.onSubscriptionsUpdated();
                }<---- that's the line of the error
            }
        }

* *更新

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    mCallbacks = (Callbacks)activity;
}

@Override
public void onDetach() {
    super.onDetach();
    mCallbacks = null;
}
4

1 回答 1

2

您的mCallbacks变量可能为空。使用防御性编程并null在调用方法之前进行检查。此外,不要检查布尔值是否为假,只需使用非!逻辑运算符即可。

@Override
protected void onPostExecute(Void v) {
    if (!this.isCancelled()){
        Log.d(TAG, "chiedo aggiornamento updateUI");
        if (mCallbacks != null) {
            mCallbacks.onSubscriptionsUpdated();
        }
    }
}
于 2013-09-18T15:22:16.513 回答