2

'導致的儀表運行失敗我正在處理通知,Asynctasks和廣播接收者的課程項目。我有三個測試運行,第一個測試失敗,堆棧跟蹤錯誤:如何糾正由於'java.lang.IllegalArgumentException''

測試運行失敗,以至完成。原因:'由於'java.lang.IllegalArgumentException'導致檢測運行失敗。檢查設備logcat的詳細信息

Logcat是巨大的。如果你能告訴我我可能在尋找什麼,我可以用標籤:函數來縮小它。

其他兩個測試運行得很好。

下面是第一個類文件,我在Eclipse中沒有顯示錯誤。

public class MainActivity extends Activity implements SelectionListener { 

     public static final String TWEET_FILENAME = "tweets.txt"; 
     public static final String[] FRIENDS = { "taylorswift13", "msrebeccablack", 
     "ladygaga" }; 
     public static final String DATA_REFRESHED_ACTION ="course.labs.notificationslab.DATA_REFRESHED"; 

     private static final int NUM_FRIENDS = 3; 
     private static final String URL_LGAGA = "https://d396qusza40orc.cloudfront.net/android%2FLabs%2FUserNotifications%2Fladygaga.txt"; 
     private static final String URL_RBLACK = "https://d396qusza40orc.cloudfront.net/android%2FLabs%2FUserNotifications%2Frebeccablack.txt"; 
     private static final String URL_TSWIFT = "https://d396qusza40orc.cloudfront.net/android%2FLabs%2FUserNotifications%2Ftaylorswift.txt"; 
     private static final String TAG = "Lab-Notifications"; 
     private static final long TWO_MIN = 2 * 60 * 1000; 
     private FragmentManager mFragmentManager; 
     private FriendsFragment mFriendsFragment; 
     private boolean mIsFresh; 
     private BroadcastReceiver mRefreshReceiver; 
     private int mFeedSelected = UNSELECTED; 
     private FeedFragment mFeedFragment; 
     private String[] mRawFeeds = new String[3]; 
     private String[] mProcessedFeeds = new String[3]; 

@Override 
     protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     mFragmentManager = getFragmentManager(); 
     addFriendsFragment(); 
    // The feed is fresh if it was downloaded less than 2 minutes ago 
     mIsFresh = (System.currentTimeMillis() - getFileStreamPath(
      TWEET_FILENAME).lastModified()) < TWO_MIN; 

     ensureData(); 

} 

// Add Friends Fragment to Activity 
     private void addFriendsFragment() { 

     mFriendsFragment = new FriendsFragment(); 
     mFriendsFragment.setArguments(getIntent().getExtras()); 

     FragmentTransaction transaction = mFragmentManager.beginTransaction(); 
     transaction.add(R.id.fragment_container, mFriendsFragment); 

     transaction.commit(); 
} 

// If stored Tweets are not fresh, reload them from network 
// Otherwise, load them from file 
     private void ensureData() { 

    log("In ensureData(), mIsFresh:" + mIsFresh); 

     if (!mIsFresh) { 

     // TODO: 
     // Show a Toast Notification to inform user that 
     // the app is "Downloading Tweets from Network" 
     log ("Issuing Toast Message"); 
     Toast.makeText(getApplicationContext(), "refreshing Tweets",Toast.LENGTH_LONG).show(); 


     // TODO: 
     // Start new AsyncTask to download Tweets from network 
     new DownloaderTask(MainActivity.this).execute(MainActivity.URL_LGAGA,MainActivity.URL_RBLACK,MainActivity.URL_TSWIFT); 





     // Set up a BroadcastReceiver to receive an Intent when download 
     // finishes. 
      mRefreshReceiver = new BroadcastReceiver() { 
      @Override 
      public void onReceive(Context context, Intent intent) { 

       log("BroadcastIntent received in MainActivity"); 

       // TODO:     
       // Check to make sure this is an ordered broadcast 
       // Let sender know that the Intent was received 
       // by setting result code to RESULT_OK 
       sendOrderedBroadcast(new Intent(), null, null, null, RESULT_OK, null, null); 

      } 
     }; 

    } else { 

     loadTweetsFromFile(); 
     parseJSON(); 
     updateFeed(); 

    } 
} 

// Called when new Tweets have been downloaded 
public void setRefreshed(String[] feeds) { 

    mRawFeeds[0] = feeds[0]; 
    mRawFeeds[1] = feeds[1]; 
    mRawFeeds[2] = feeds[2]; 

    parseJSON(); 
    updateFeed(); 
    mIsFresh = true; 

}; 

// Called when a Friend is clicked on 
@Override 
public void onItemSelected(int position) { 

    mFeedSelected = position; 
    mFeedFragment = addFeedFragment(); 

    if (mIsFresh) { 
     updateFeed(); 
    } 
} 

// Calls FeedFragement.update, passing in the 
// the tweets for the currently selected friend 

void updateFeed() { 

    if (null != mFeedFragment) 

     mFeedFragment.update(mProcessedFeeds[mFeedSelected]); 

} 

// Add FeedFragment to Activity 
private FeedFragment addFeedFragment() { 
    FeedFragment feedFragment; 
    feedFragment = new FeedFragment(); 

    FragmentTransaction transaction = mFragmentManager.beginTransaction(); 

    transaction.replace(R.id.fragment_container, feedFragment); 
    transaction.addToBackStack(null); 

    transaction.commit(); 
    mFragmentManager.executePendingTransactions(); 
    return feedFragment; 

} 

// Register the BroadcastReceiver 
@Override 
protected void onResume() { 
    super.onResume(); 

    // TODO: 
    // Register the BroadcastReceiver to receive a 
    // DATA_REFRESHED_ACTION broadcast 
    IntentFilter intentFilter = new IntentFilter(DATA_REFRESHED_ACTION); 
     registerReceiver(mRefreshReceiver, intentFilter); 


} 

@Override 
protected void onPause() { 

    // TODO: 
    // Unregister the BroadcastReceiver 
    unregisterReceiver(mRefreshReceiver); 



    super.onPause(); 

} 

// Convert raw Tweet data (in JSON format) into text for display 

public void parseJSON() { 

    JSONArray[] JSONFeeds = new JSONArray[NUM_FRIENDS]; 

    for (int i = 0; i < NUM_FRIENDS; i++) { 
     try { 
      JSONFeeds[i] = new JSONArray(mRawFeeds[i]); 
     } catch (JSONException e) { 
      e.printStackTrace(); 
     } 

     String name = ""; 
     String tweet = ""; 

     JSONArray tmp = JSONFeeds[i]; 

     // string buffer for twitter feeds 
     StringBuffer tweetRec = new StringBuffer(""); 

     for (int j = 0; j < tmp.length(); j++) { 
      try { 
       tweet = tmp.getJSONObject(j).getString("text"); 
       JSONObject user = (JSONObject) tmp.getJSONObject(j).get(
         "user"); 
       name = user.getString("name"); 

      } catch (JSONException e) { 
       e.printStackTrace(); 
      } 

      tweetRec.append(name + " - " + tweet + "\n\n"); 
     } 

     mProcessedFeeds[i] = tweetRec.toString(); 

    } 
} 

// Retrieve feeds text from a file 
// Store them in mRawTextFeed[] 

private void loadTweetsFromFile() { 
    BufferedReader reader = null; 

    try { 
     FileInputStream fis = openFileInput(TWEET_FILENAME); 
     reader = new BufferedReader(new InputStreamReader(fis)); 
     String s = null; 
     int i = 0; 
     while (null != (s = reader.readLine()) && i < NUM_FRIENDS) { 
      mRawFeeds[i] = s; 
      i++; 
     } 
    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } finally { 
     if (null != reader) { 
      try { 
       reader.close(); 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } 
     } 
    } 
} 

// Simplified log output method 
private void log(String msg) { 
    try { 
     Thread.sleep(500); 
    } catch (InterruptedException e) { 
     e.printStackTrace(); 
    } 
    Log.i(TAG, msg); 
} 

}

這是第二類文件,並顯示一個警告,即表示不使用局部變量notificationBuilder。

public class MainActivity extends Activity implements SelectionListener { 

     public static final String TWEET_FILENAME = "tweets.txt"; 
     public static final String[] FRIENDS = { "taylorswift13", "msrebeccablack", 
     "ladygaga" }; 
     public static final String DATA_REFRESHED_ACTION = "course.labs.notificationslab.DATA_REFRESHED"; 

     private static final int NUM_FRIENDS = 3; 
     private static final String URL_LGAGA = "https://d396qusza40orc.cloudfront.net/android%2FLabs%2FUserNotifications%2Fladygaga.txt"; 
     private static final String URL_RBLACK = "https://d396qusza40orc.cloudfront.net/android%2FLabs%2FUserNotifications%2Frebeccablack.txt"; 
     private static final String URL_TSWIFT = "https://d396qusza40orc.cloudfront.net/android%2FLabs%2FUserNotifications%2Ftaylorswift.txt"; 
     private static final String TAG = "Lab-Notifications"; 
     private static final long TWO_MIN = 2 * 60 * 1000; 
     private static final int UNSELECTED = -1; 

     private FragmentManager mFragmentManager; 
     private FriendsFragment mFriendsFragment; 
     private boolean mIsFresh; 
     private BroadcastReceiver mRefreshReceiver; 
     private int mFeedSelected = UNSELECTED; 
     private FeedFragment mFeedFragment; 
     private String[] mRawFeeds = new String[3]; 
     private String[] mProcessedFeeds = new String[3]; 

@Override 
     protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     mFragmentManager = getFragmentManager(); 
     addFriendsFragment(); 

    // The feed is fresh if it was downloaded less than 2 minutes ago 
     mIsFresh = (System.currentTimeMillis() - getFileStreamPath(
      TWEET_FILENAME).lastModified()) < TWO_MIN; 

     ensureData(); 

} 

// Add Friends Fragment to Activity 
     private void addFriendsFragment() { 

     mFriendsFragment = new FriendsFragment(); 
     mFriendsFragment.setArguments(getIntent().getExtras()); 

     FragmentTransaction transaction = mFragmentManager.beginTransaction(); 
     transaction.add(R.id.fragment_container, mFriendsFragment); 

     transaction.commit(); 
} 

// If stored Tweets are not fresh, reload them from network 
// Otherwise, load them from file 
     private void ensureData() { 

    log("In ensureData(), mIsFresh:" + mIsFresh); 

     if (!mIsFresh) { 

     // TODO: 
     // Show a Toast Notification to inform user that 
     // the app is "Downloading Tweets from Network" 
     log ("Issuing Toast Message"); 
       Toast.makeText(getApplicationContext(), "refreshing Tweets",Toast.LENGTH_LONG).show(); 


     // TODO: 
     // Start new AsyncTask to download Tweets from network 
      new DownloaderTask(MainActivity.this).execute(MainActivity.URL_LGAGA,MainActivity.URL_RBLACK,MainActivity.URL_TSWIFT); 





     // Set up a BroadcastReceiver to receive an Intent when download 
     // finishes. 
      mRefreshReceiver = new BroadcastReceiver() { 
      @Override 
        public void onReceive(Context context, Intent intent) { 

       log("BroadcastIntent received in MainActivity"); 

       // TODO:     
       // Check to make sure this is an ordered broadcast 
       // Let sender know that the Intent was received 
       // by setting result code to RESULT_OK 
         sendOrderedBroadcast(new Intent(), null, null, null, RESULT_OK, null, null); 

      } 
     }; 

    } else { 

      loadTweetsFromFile(); 
      parseJSON(); 
      updateFeed(); 

    } 
} 

// Called when new Tweets have been downloaded 
     public void setRefreshed(String[] feeds) { 

     mRawFeeds[0] = feeds[0]; 
     mRawFeeds[1] = feeds[1]; 
     mRawFeeds[2] = feeds[2]; 

     parseJSON(); 
     updateFeed(); 
     mIsFresh = true; 

}; 

// Called when a Friend is clicked on 
@Override 
     public void onItemSelected(int position) { 

     mFeedSelected = position; 
     mFeedFragment = addFeedFragment(); 

     if (mIsFresh) { 
       updateFeed(); 
    } 
} 

// Calls FeedFragement.update, passing in the 
// the tweets for the currently selected friend 

    void updateFeed() { 

      if (null != mFeedFragment) 

       mFeedFragment.update(mProcessedFeeds[mFeedSelected]); 

} 

// Add FeedFragment to Activity 
     private FeedFragment addFeedFragment() { 
     FeedFragment feedFragment; 
     feedFragment = new FeedFragment(); 

     FragmentTransaction transaction = mFragmentManager.beginTransaction(); 

     transaction.replace(R.id.fragment_container, feedFragment); 
     transaction.addToBackStack(null); 

     transaction.commit(); 
     mFragmentManager.executePendingTransactions(); 
     return feedFragment; 

} 

// Register the BroadcastReceiver 
@Override 
     protected void onResume() { 
     super.onResume(); 

    // TODO: 
    // Register the BroadcastReceiver to receive a 
    // DATA_REFRESHED_ACTION broadcast 
     IntentFilter intentFilter = new IntentFilter(DATA_REFRESHED_ACTION); 
      registerReceiver(mRefreshReceiver, intentFilter); 


} 

@Override 
     protected void onPause() { 

    // TODO: 
    // Unregister the BroadcastReceiver 
     unregisterReceiver(mRefreshReceiver); 



     super.onPause(); 

} 

// Convert raw Tweet data (in JSON format) into text for display 

     public void parseJSON() { 

     JSONArray[] JSONFeeds = new JSONArray[NUM_FRIENDS]; 

     for (int i = 0; i < NUM_FRIENDS; i++) { 
       try { 
        JSONFeeds[i] = new JSONArray(mRawFeeds[i]); 
      } catch (JSONException e) { 
       e.printStackTrace(); 
     } 

      String name = ""; 
      String tweet = ""; 

      JSONArray tmp = JSONFeeds[i]; 

     // string buffer for twitter feeds 
      StringBuffer tweetRec = new StringBuffer(""); 

      for (int j = 0; j < tmp.length(); j++) { 
       try { 
        tweet = tmp.getJSONObject(j).getString("text"); 
        JSONObject user = (JSONObject) tmp.getJSONObject(j).get(
         "user"); 
        name = user.getString("name"); 

       } catch (JSONException e) { 
        e.printStackTrace(); 
      } 

       tweetRec.append(name + " - " + tweet + "\n\n"); 
     } 

      mProcessedFeeds[i] = tweetRec.toString(); 

    } 
} 

// Retrieve feeds text from a file 
// Store them in mRawTextFeed[] 

     private void loadTweetsFromFile() { 
     BufferedReader reader = null; 

     try { 
      FileInputStream fis = openFileInput(TWEET_FILENAME); 
      reader = new BufferedReader(new InputStreamReader(fis)); 
      String s = null; 
      int i = 0; 
      while (null != (s = reader.readLine()) && i < NUM_FRIENDS) { 
       mRawFeeds[i] = s; 
       i++; 
     } 
     } catch (FileNotFoundException e) { 
      e.printStackTrace(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } finally { 
      if (null != reader) { 
       try { 
        reader.close(); 
       } catch (IOException e) { 
        e.printStackTrace(); 
      } 
     } 
    } 
} 

// Simplified log output method 
     private void log(String msg) { 
     try { 
      Thread.sleep(500); 
     } catch (InterruptedException e) { 
      e.printStackTrace(); 
    } 
    Log.i(TAG, msg); 
} 
} 

我不知道我在這裏弄錯了什麼?這個應用程序應該顯示來自三個人的推特供稿,第一個人只顯示推文正在下載的消息,但從不顯示第一人的推特供稿,該應用程序運行經過這一點並顯示第二人飼料,然後拋出列出的堆棧跟蹤,或者交替顯示堆棧跟蹤錯誤,第一個人員視圖未顯示(提要存儲在文本文件中並在androidManifest.xml中聲明,因爲模擬器實際上無法連接到Web)文本文件是預先寫好並由教師在清單中聲明,所以我不相信問題在於任何一個,我是Java編程的新手,我不是很精通,所以我確信我把它搞砸了。在第二個.class文件中。

這裏是只有標籤的LogCat:對於android運行時,它是什麼引用了致命錯誤,我是如此新,我不知道我在哪裏尋找行號。

02-16 17:11:06.606: D/AndroidRuntime(5278): Shutting down VM 
02-16 17:11:06.704: E/AndroidRuntime(5278): FATAL EXCEPTION: main 
02-16 17:11:06.704: E/AndroidRuntime(5278): java.lang.RuntimeException: Unable to pause  activity {course.labs.notificationslab/course.labs.notificationslab.MainActivity}: java.lang.IllegalArgumentException: Receiver not registered: null 
02-16 17:11:06.704: E/AndroidRuntime(5278):  at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3064) 
02-16 17:11:06.704: E/AndroidRuntime(5278):  at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3019) 
02-16 17:11:06.704: E/AndroidRuntime(5278):  at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2997) 
02-16 17:11:06.704: E/AndroidRuntime(5278):  at android.app.ActivityThread.access$800(ActivityThread.java:141) 
02-16 17:11:06.704: E/AndroidRuntime(5278):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1273) 
02-16 17:11:06.704: E/AndroidRuntime(5278):  at android.os.Handler.dispatchMessage(Handler.java:99) 
02-16 17:11:06.704: E/AndroidRuntime(5278):  at android.os.Looper.loop(Looper.java:137) 
02-16 17:11:06.704: E/AndroidRuntime(5278):  at android.app.ActivityThread.main(ActivityThread.java:5103) 
02-16 17:11:06.704: E/AndroidRuntime(5278):  at java.lang.reflect.Method.invokeNative(Native Method) 
02-16 17:11:06.704: E/AndroidRuntime(5278):  at java.lang.reflect.Method.invoke(Method.java:525) 
02-16 17:11:06.704: E/AndroidRuntime(5278):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 
02-16 17:11:06.704: E/AndroidRuntime(5278):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
02-16 17:11:06.704: E/AndroidRuntime(5278):  at dalvik.system.NativeStart.main(Native Method) 
02-16 17:11:06.704: E/AndroidRuntime(5278): Caused by: java.lang.IllegalArgumentException: Receiver not registered: null 
02-16 17:11:06.704: E/AndroidRuntime(5278):  at android.app.LoadedApk.forgetReceiverDispatcher(LoadedApk.java:662) 
02-16 17:11:06.704: E/AndroidRuntime(5278):  at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:1372) 
02-16 17:11:06.704: E/AndroidRuntime(5278):  at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:468) 
02-16 17:11:06.704: E/AndroidRuntime(5278):  at course.labs.notificationslab.MainActivity.onPause(MainActivity.java:196) 
02-16 17:11:06.704: E/AndroidRuntime(5278):  at android.app.Activity.performPause(Activity.java:5235) 
02-16 17:11:06.704: E/AndroidRuntime(5278):  at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1233) 
02-16 17:11:06.704: E/AndroidRuntime(5278):  at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3050) 
02-16 17:11:06.704: E/AndroidRuntime(5278):  ... 12 more 
02-16 17:15:19.514: D/AndroidRuntime(5361): Shutting down VM 
02-16 17:15:19.646: E/AndroidRuntime(5361): FATAL EXCEPTION: main 
02-16 17:15:19.646: E/AndroidRuntime(5361): java.lang.RuntimeException: Unable to pause activity {course.labs.notificationslab/course.labs.notificationslab.MainActivity}: java.lang.IllegalArgumentException: Receiver not registered: null 
02-16 17:15:19.646: E/AndroidRuntime(5361):  at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3064) 
02-16 17:15:19.646: E/AndroidRuntime(5361):  at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3019) 
02-16 17:15:19.646: E/AndroidRuntime(5361):  at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2997) 
02-16 17:15:19.646: E/AndroidRuntime(5361):  at android.app.ActivityThread.access$800(ActivityThread.java:141) 
02-16 17:15:19.646: E/AndroidRuntime(5361):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1273) 
02-16 17:15:19.646: E/AndroidRuntime(5361):  at android.os.Handler.dispatchMessage(Handler.java:99) 
02-16 17:15:19.646: E/AndroidRuntime(5361):  at android.os.Looper.loop(Looper.java:137) 
02-16 17:15:19.646: E/AndroidRuntime(5361):  at android.app.ActivityThread.main(ActivityThread.java:5103) 
02-16 17:15:19.646: E/AndroidRuntime(5361):  at java.lang.reflect.Method.invokeNative(Native Method) 
02-16 17:15:19.646: E/AndroidRuntime(5361):  at java.lang.reflect.Method.invoke(Method.java:525) 
02-16 17:15:19.646: E/AndroidRuntime(5361):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 
02-16 17:15:19.646: E/AndroidRuntime(5361):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
02-16 17:15:19.646: E/AndroidRuntime(5361):  at dalvik.system.NativeStart.main(Native Method) 
02-16 17:15:19.646: E/AndroidRuntime(5361): Caused by: java.lang.IllegalArgumentException: Receiver not registered: null 
02-16 17:15:19.646: E/AndroidRuntime(5361):  at android.app.LoadedApk.forgetReceiverDispatcher(LoadedApk.java:662) 
02-16 17:15:19.646: E/AndroidRuntime(5361):  at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:1372) 
02-16 17:15:19.646: E/AndroidRuntime(5361):  at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:468) 
02-16 17:15:19.646: E/AndroidRuntime(5361):  at course.labs.notificationslab.MainActivity.onPause(MainActivity.java:196) 
02-16 17:15:19.646: E/AndroidRuntime(5361):  at android.app.Activity.performPause(Activity.java:5235) 
02-16 17:15:19.646: E/AndroidRuntime(5361):  at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1233) 
02-16 17:15:19.646: E/AndroidRuntime(5361):  at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3050) 
02-16 17:15:19.646: E/AndroidRuntime(5361):  ... 12 more 
02-16 17:49:19.994: D/AndroidRuntime(5451): Shutting down VM 
02-16 17:49:20.104: E/AndroidRuntime(5451): FATAL EXCEPTION: main 
02-16 17:49:20.104: E/AndroidRuntime(5451): java.lang.RuntimeException: Unable to pause activity {course.labs.notificationslab/course.labs.notificationslab.MainActivity}: java.lang.IllegalArgumentException: Receiver not registered: null 
02-16 17:49:20.104: E/AndroidRuntime(5451):  at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3064) 
02-16 17:49:20.104: E/AndroidRuntime(5451):  at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3019) 
02-16 17:49:20.104: E/AndroidRuntime(5451):  at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2997) 
02-16 17:49:20.104: E/AndroidRuntime(5451):  at android.app.ActivityThread.access$800(ActivityThread.java:141) 
02-16 17:49:20.104: E/AndroidRuntime(5451):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1273) 
02-16 17:49:20.104: E/AndroidRuntime(5451):  at android.os.Handler.dispatchMessage(Handler.java:99) 
02-16 17:49:20.104: E/AndroidRuntime(5451):  at android.os.Looper.loop(Looper.java:137) 
02-16 17:49:20.104: E/AndroidRuntime(5451):  at android.app.ActivityThread.main(ActivityThread.java:5103) 
02-16 17:49:20.104: E/AndroidRuntime(5451):  at java.lang.reflect.Method.invokeNative(Native Method) 
02-16 17:49:20.104: E/AndroidRuntime(5451):  at java.lang.reflect.Method.invoke(Method.java:525) 
02-16 17:49:20.104: E/AndroidRuntime(5451):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 
02-16 17:49:20.104: E/AndroidRuntime(5451):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
02-16 17:49:20.104: E/AndroidRuntime(5451):  at dalvik.system.NativeStart.main(Native Method) 
02-16 17:49:20.104: E/AndroidRuntime(5451): Caused by: java.lang.IllegalArgumentException: Receiver not registered: null 
02-16 17:49:20.104: E/AndroidRuntime(5451):  at android.app.LoadedApk.forgetReceiverDispatcher(LoadedApk.java:662) 
02-16 17:49:20.104: E/AndroidRuntime(5451):  at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:1372) 
02-16 17:49:20.104: E/AndroidRuntime(5451):  at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:468) 
02-16 17:49:20.104: E/AndroidRuntime(5451):  at course.labs.notificationslab.MainActivity.onPause(MainActivity.java:196) 
02-16 17:49:20.104: E/AndroidRuntime(5451):  at android.app.Activity.performPause(Activity.java:5235) 
02-16 17:49:20.104: E/AndroidRuntime(5451):  at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1233) 
02-16 17:49:20.104: E/AndroidRuntime(5451):  at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3050) 
02-16 17:49:20.104: E/AndroidRuntime(5451):  ... 12 more 
+0

的logcat的必須顯示在其上線是EXCE請檢查,它指向哪條線? – user2450263

回答

0

您還沒有在onPause()中初始化mRefreshReciver。

嘗試初始化mRefreshReceiver而不管mIsFresh on ensureData()。

+0

你會願意展示一個語法正確的例子,這是我還沒有學到的一件事。我試圖通過java快速語法參考來理解初始化塊的語法,但本書中介紹的示例與// Static int [] array = new int [5]的初始化塊語句有關。呼叫。我不知道如何關聯這個項目的正確呼叫。 –

1

你必須檢查是否mRefreshReciver是在onPause方法無效

if(mRefreshReceiver != null) 
{ 
unregisterReceiver(mRefreshReceiver); 
} 

這將解決您的問題,並測試將通過;)

+0

它沒有真正的幫助? – downhand

0

在mRefreshReceiver的頂部檢查伊萬已經提到的,你需要添加空校驗爲mCallback,以及在onPostExecute():

if (mCallback != null) { 
    mCallback.notifyDataRefreshed(strings); 
}