问题
I am working on a course project that deals with notifications,Asynctasks, and broadcast Recievers. i have three tests to run, the first test fails with the stack trace error of:
Test failed to run to completion. Reason: 'Instrumentation run failed due to 'java.lang.IllegalArgumentException''. Check device logcat for details
the Logcat is huge. if you can tell me what i might be looking for i can narrow it with the tag: function.
the other two tests run just fine.
below is the first class file, i show no errors in 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);
}
}
this is the second class file and it shows a warning, that says the local variable notificationBuilder is not used.
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);
}
}
i'm not sure what i've got wrong here? this application is supposed to show twitter feeds from three people, the first person only shows the message that the tweets are being downloaded, but never shows the twitter feed for the first person, the app runs past this point and shows the second persons feed then throws the listed stacktrace, or alternately shows a stack trace error that the first persons view was not displayed ( the feeds are stored in a text file and declared in the androidManifest.xml since the emulator cannot actually connect to the web) the text file was pre-written and declared in the manifest by the instructor so i don't beleive the issue lies with any of that, i'm new to Java programming and i'm not very well versed so i'm sure i screwed it up somewhere in the second .class file.
here is the LogCat with just the Tag: for the android runtime as it is what referenced the fatal error, i am so new i don't know where i am looking for the line number.
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
回答1:
You have to check if mRefreshReciver is null in onPause method
if(mRefreshReceiver != null)
{
unregisterReceiver(mRefreshReceiver);
}
This will solve your problem and test will pass ;)
回答2:
You have not initialized mRefreshReciver in onPause().
Try to initialize mRefreshReceiver regardless to mIsFresh on ensureData().
回答3:
On top of the mRefreshReceiver check that Ivan has mentioned, you need to add a null check for mCallback as well in onPostExecute():
if (mCallback != null) {
mCallback.notifyDataRefreshed(strings);
}
来源:https://stackoverflow.com/questions/22085760/how-to-correct-a-instrumentation-run-failed-due-to-java-lang-illegalargumentex