由于'java.lang.IllegalArgumentException',如何纠正'Instrumentation运行失败' [英] how to correct a 'Instrumentation run failed due to 'java.lang.IllegalArgumentException''

查看:588
本文介绍了由于'java.lang.IllegalArgumentException',如何纠正'Instrumentation运行失败'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个课程项目,该项目处理通知,异步任务和广播接收器.我要运行三个测试,第一个测试失败,堆栈跟踪错误为:

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:

测试无法完成.原因:由于'java.lang.IllegalArgumentException",仪器运行失败.检查设备日志以获得详细信息

Test failed to run to completion. Reason: 'Instrumentation run failed due to 'java.lang.IllegalArgumentException''. Check device logcat for details

Logcat很大.如果您能告诉我我要寻找的内容,可以使用tag:function来缩小它的范围.

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.

下面是第一类文件,我在Eclipse中没有显示错误.

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);
}

}

这是第二类文件,它显示警告,提示未使用本地变量notificationBuilder.

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);
}
}

我不确定我在这里错了吗?该应用程序应该显示三人的Twitter提要,第一人仅显示正在下载推文的消息,但从不显示第一人的Twitter提要,该应用程序将运行到这一点并显示第二人的提要抛出列出的stacktrace,或交替显示未显示第一人称视角的堆栈跟踪错误(提要存储在文本文件中,并在androidManifest.xml中声明,因为仿真器实际上无法连接到网络),该文本文件为由教师预先编写并声明在清单中,所以我不认为问题出在其中,我是Java编程的新手,我也不是很精通,所以我确定我将它固定在某个地方在第二个.class文件中.

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.

这是仅带标签的LogCat:对于android运行时,因为它引用的是致命错误,我是如此新奇,我不知道我在哪里寻找行号.

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

推荐答案

您必须检查onPause方法中的mRefreshReciver是否为空

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 ;)

这篇关于由于'java.lang.IllegalArgumentException',如何纠正'Instrumentation运行失败'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆