cara memperbaiki 'Instrumentasi yang gagal karena' java.lang.IllegalArgumentException ''

Casey French 02/28/2014. 3 answers, 4.687 views
android android eclipse android-asynctask broadcastreceiver android-notifications

Saya sedang mengerjakan proyek kursus yang berhubungan dengan notifikasi, Asynctasks, dan Penyiar siaran. Saya memiliki tiga tes untuk dijalankan, tes pertama gagal dengan kesalahan tumpukan jejak:

Tes gagal dijalankan hingga selesai. Alasan: 'Pelaksanaan instrumentasi gagal karena' java.lang.IllegalArgumentException ''. Periksa logcat perangkat untuk detailnya

Logcat sangat besar. jika Anda dapat memberi tahu saya apa yang mungkin saya cari, saya dapat mempersempitnya dengan tag: function.

dua tes lainnya berjalan dengan baik.

di bawah ini adalah file kelas pertama, saya tidak menunjukkan kesalahan dalam 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);
} 

}

ini adalah file kelas kedua dan itu menunjukkan peringatan, yang mengatakan notificationBuilder variabel lokal tidak digunakan.

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

Saya tidak yakin apa yang saya lakukan salah di sini? aplikasi ini seharusnya menunjukkan feed twitter dari tiga orang, orang pertama hanya menunjukkan pesan bahwa tweet tersebut sedang diunduh, tetapi tidak pernah menunjukkan umpan twitter untuk orang pertama, aplikasi berjalan melewati titik ini dan menunjukkan umpan orang kedua kemudian melempar stacktrace yang terdaftar, atau secara bergantian menampilkan kesalahan jejak tumpukan bahwa tampilan orang pertama tidak ditampilkan (umpan disimpan dalam file teks dan dideklarasikan di androidManifest.xml karena emulator tidak dapat benar-benar terhubung ke web) file teks adalah pra-ditulis dan dinyatakan dalam manifes oleh instruktur sehingga saya tidak percaya masalah terletak dengan semua itu, saya baru pemrograman Java dan saya tidak sangat fasih jadi saya yakin saya mengacaukannya di suatu tempat di file .class kedua.

di sini adalah LogCat dengan hanya Tag: untuk runtime android seperti apa yang direferensikan kesalahan fatal, saya sangat baru saya tidak tahu di mana saya mencari nomor baris.

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 

3 Answers


Ivan 03/01/2014.

Anda harus memeriksa apakah mRefreshReciver adalah null dalam metode onPause

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

Ini akan menyelesaikan masalah Anda dan tes akan berlalu;)


kstachniuk 02/28/2014.

Anda belum menginisialisasi mRefreshReciver di onPause ().

Cobalah untuk menginisialisasi mRefreshReceiver terlepas ke mIsFresh pada memastikanData ().


downhand 08/07/2015.

Di atas pemeriksaan mRefreshReceiver yang Ivan sebutkan, Anda perlu menambahkan pemeriksaan null untuk mCallback juga di onPostExecute ():

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

Related questions

Hot questions

Language

Popular Tags