无法启动接收器com.parse.ParseBroadcastReceiver:ConcurrentModificationException

时间:2014-08-18 14:56:18

标签: android concurrency parse-platform push-notification

我正在使用解析sdk 1.5.1版本在Samsung Note 2上崩溃,以下是我的Application类代码。

@Override
    public void onCreate()
    {       
        super.onCreate();

        try
        {


            Parse.enableLocalDatastore(this);
            // Live acc
            Parse.initialize(this, "XXXXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXX");

            //Enable to receive push
            PushService.setDefaultPushCallback(this, RespondToPushActivity.class);

            Log.d("System out", "Parse ID----> "+ParseInstallation.getCurrentInstallation().getString("deviceToken"));
            Constants.PARSEID = ParseInstallation.getCurrentInstallation().getString("deviceToken");



            ParseInstallation.getCurrentInstallation().saveInBackground();
        }
        catch (Exception e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }    


    }

现在我得到了下面的堆栈跟踪:

java.lang.RuntimeException: java.util.ConcurrentModificationException

at com.parse.PushRouter$8$1.run(PushRouter.java:235)

at android.os.Handler.handleCallback(Handler.java:730)

at android.os.Handler.dispatchMessage(Handler.java:92)

at android.os.Looper.loop(Looper.java:176)

at android.app.ActivityThread.main(ActivityThread.java:5419)

at java.lang.reflect.Method.invokeNative(Native Method)

at java.lang.reflect.Method.invoke(Method.java:525)

at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)

at dalvik.system.NativeStart.main(Native Method)

Caused by: java.util.ConcurrentModificationException

at java.util.LinkedList$LinkIterator.next(LinkedList.java:124)

at com.parse.ParseObject.mergeREST(ParseObject.java:928)

at com.parse.OfflineStore$13$2.then(OfflineStore.java:765)

at com.parse.OfflineStore$13$2.then(OfflineStore.java:762)

at com.parse.Task$10.run(Task.java:448)

at com.parse.Task$ImmediateExecutor.execute(Task.java:673)

at com.parse.Task.completeImmediately(Task.java:444)

at com.parse.Task.continueWith(Task.java:318)

at com.parse.Task.continueWith(Task.java:329)

at com.parse.Task$8.then(Task.java:381)

at com.parse.Task$8.then(Task.java:373)

at com.parse.Task$11.run(Task.java:481)

at com.parse.Task$ImmediateExecutor.execute(Task.java:673)

at com.parse.Task.completeAfterTask(Task.java:477)

at com.parse.Task.continueWithTask(Task.java:353)

at com.parse.Task.onSuccess(Task.java:373)

at com.parse.Task.onSuccess(Task.java:393)

at com.parse.OfflineStore$13.then(OfflineStore.java:762)

at com.parse.OfflineStore$13.then(OfflineStore.java:721)

at com.parse.Task$11.run(Task.java:481)

at com.parse.Task$ImmediateExecutor.execute(Task.java:673)

at com.parse.Task.completeAfterTask(Task.java:477)

at com.parse.Task.continueWithTask(Task.java:353)

at com.parse.Task.continueWithTask(Task.java:364)

at com.parse.Task$9.then(Task.java:410)

at com.parse.Task$9.then(Task.java:402)

at com.parse.Task$11.run(Task.java:481)

at com.parse.Task$ImmediateExecutor.execute(Task.java:673)

at com.parse.Task.completeAfterTask(Task.java:477)

at com.parse.Task.access$400(Task.java:22)

at com.parse.Task$7.then(Task.java:346)

at com.parse.Task$7.then(Task.java:343)

at com.parse.Task.runContinuations(Task.java:510)

at com.parse.Task.access$800(Task.java:22)

at com.parse.Task$TaskCompletionSource.trySetResult(Task.java:565)

at com.parse.Task$TaskCompletionSource.setResult(Task.java:599)

at com.parse.Task$11$1.then(Task.java:493)

at com.parse.Task$11$1.then(Task.java:485)

at com.parse.Task$10.run(Task.java:448)

at com.parse.Task$ImmediateExecutor.execute(Task.java:673)

at com.parse.Task.completeImmediately(Task.java:444)

at com.parse.Task.continueWith(Task.java:318)

at com.parse.Task.continueWith(Task.java:329)

at com.parse.Task$11.run(Task.java:485)

at com.parse.Task$ImmediateExecutor.execute(Task.java:673)

at com.parse.Task.completeAfterTask(Task.java:477)

at com.parse.Task.access$400(Task.java:22)

at com.parse.Task$7.then(Task.java:346)

at com.parse.Task$7.then(Task.java:343)

at com.parse.Task.runContinuations(Task.java:510)

at com.parse.Task.access$800(Task.java:22)

at com.parse.Task$TaskCompletionSource.trySetResult(Task.java:565)

at com.parse.Task$TaskCompletionSource.setResult(Task.java:599)

at com.parse.Task$11$1.then(Task.java:493)

at com.parse.Task$11$1.then(Task.java:485)

at com.parse.Task$10.run(Task.java:448)

at com.parse.Task$ImmediateExecutor.execute(Task.java:673)

at com.parse.Task.completeImmediately(Task.java:444)

at com.parse.Task.access$300(Task.java:22)

at com.parse.Task$6.then(Task.java:311)

at com.parse.Task$6.then(Task.java:308)

at com.parse.Task.runContinuations(Task.java:510)

at com.parse.Task.access$800(Task.java:22)

at com.parse.Task$TaskCompletionSource.trySetResult(Task.java:565)

at com.parse.Task$TaskCompletionSource.setResult(Task.java:599)

at com.parse.Task$11$1.then(Task.java:493)

at com.parse.Task$11$1.then(Task.java:485)

at com.parse.Task$10.run(Task.java:448)

at com.parse.Task$ImmediateExecutor.execute(Task.java:673)

at com.parse.Task.completeImmediately(Task.java:444)

at com.parse.Task.access$300(Task.java:22)

at com.parse.Task$6.then(Task.java:311)

at com.parse.Task$6.then(Task.java:308)

at com.parse.Task.runContinuations(Task.java:510)

at com.parse.Task.access$800(Task.java:22)

at com.parse.Task$TaskCompletionSource.trySetResult(Task.java:565)

at com.parse.Task$TaskCompletionSource.setResult(Task.java:599)

at com.parse.Task$11$1.then(Task.java:493)

at com.parse.Task$11$1.then(Task.java:485)

at com.parse.Task$10.run(Task.java:448)

at com.parse.Task$ImmediateExecutor.execute(Task.java:673)

at com.parse.Task.completeImmediately(Task.java:444)

at com.parse.Task.continueWith(Task.java:318)

at com.parse.Task.continueWith(Task.java:329)

at com.parse.Task$11.run(Task.java:485)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)

at java.lang.Thread.run(Thread.java:841)

[7:19:27 PM] Hiren Raval: 2nd once:

[7:19:28 PM] Hiren Raval: java.lang.RuntimeException: Unable to start receiver com.parse.ParseBroadcastReceiver: java.util.ConcurrentModificationException

at android.app.ActivityThread.handleReceiver(ActivityThread.java:2462)

at android.app.ActivityThread.access$1600(ActivityThread.java:157)

at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1365)

at android.os.Handler.dispatchMessage(Handler.java:99)

at android.os.Looper.loop(Looper.java:176)

at android.app.ActivityThread.main(ActivityThread.java:5317)

at java.lang.reflect.Method.invokeNative(Native Method)

at java.lang.reflect.Method.invoke(Method.java:511)

at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)

at dalvik.system.NativeStart.main(Native Method)

Caused by: java.util.ConcurrentModificationException

at java.util.LinkedList$LinkIterator.next(LinkedList.java:124)

at com.parse.ParseObject.mergeREST(ParseObject.java:928)

at com.parse.OfflineStore$13$2.then(OfflineStore.java:765)

at com.parse.OfflineStore$13$2.then(OfflineStore.java:762)

at com.parse.Task$10.run(Task.java:448)

at com.parse.Task$ImmediateExecutor.execute(Task.java:673)

at com.parse.Task.completeImmediately(Task.java:444)

at com.parse.Task.continueWith(Task.java:318)

at com.parse.Task.continueWith(Task.java:329)

at com.parse.Task$8.then(Task.java:381)

at com.parse.Task$8.then(Task.java:373)

at com.parse.Task$11.run(Task.java:481)

at com.parse.Task$ImmediateExecutor.execute(Task.java:673)

at com.parse.Task.completeAfterTask(Task.java:477)

at com.parse.Task.continueWithTask(Task.java:353)

at com.parse.Task.onSuccess(Task.java:373)

at com.parse.Task.onSuccess(Task.java:393)

at com.parse.OfflineStore$13.then(OfflineStore.java:762)

at com.parse.OfflineStore$13.then(OfflineStore.java:721)

at com.parse.Task$11.run(Task.java:481)

at com.parse.Task$ImmediateExecutor.execute(Task.java:673)

at com.parse.Task.completeAfterTask(Task.java:477)

at com.parse.Task.continueWithTask(Task.java:353)

at com.parse.Task.continueWithTask(Task.java:364)

at com.parse.Task$9.then(Task.java:410)

at com.parse.Task$9.then(Task.java:402)

at com.parse.Task$11.run(Task.java:481)

at com.parse.Task$ImmediateExecutor.execute(Task.java:673)

at com.parse.Task.completeAfterTask(Task.java:477)

at com.parse.Task.access$400(Task.java:22)

at com.parse.Task$7.then(Task.java:346)

at com.parse.Task$7.then(Task.java:343)

at com.parse.Task.runContinuations(Task.java:510)

at com.parse.Task.access$800(Task.java:22)

at com.parse.Task$TaskCompletionSource.trySetResult(Task.java:565)

at com.parse.Task$TaskCompletionSource.setResult(Task.java:599)

at com.parse.Task$11$1.then(Task.java:493)

at com.parse.Task$11$1.then(Task.java:485)

at com.parse.Task$10.run(Task.java:448)

at com.parse.Task$ImmediateExecutor.execute(Task.java:673)

at com.parse.Task.completeImmediately(Task.java:444)

at com.parse.Task.continueWith(Task.java:318)

at com.parse.Task.continueWith(Task.java:329)

at com.parse.Task$11.run(Task.java:485)

at com.parse.Task$ImmediateExecutor.execute(Task.java:673)

at com.parse.Task.completeAfterTask(Task.java:477)

at com.parse.Task.access$400(Task.java:22)

at com.parse.Task$7.then(Task.java:346)

at com.parse.Task$7.then(Task.java:343)

at com.parse.Task.runContinuations(Task.java:510)

at com.parse.Task.access$800(Task.java:22)

at com.parse.Task$TaskCompletionSource.trySetResult(Task.java:565)

at com.parse.Task$TaskCompletionSource.setResult(Task.java:599)

at com.parse.Task$11$1.then(Task.java:493)

at com.parse.Task$11$1.then(Task.java:485)

at com.parse.Task$10.run(Task.java:448)

at com.parse.Task$ImmediateExecutor.execute(Task.java:673)

at com.parse.Task.completeImmediately(Task.java:444)

at com.parse.Task.continueWith(Task.java:318)

at com.parse.Task.continueWith(Task.java:329)

at com.parse.Task$11.run(Task.java:485)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)

at java.lang.Thread.run(Thread.java:856)

如果有人能解决此问题,请与我们联系。 我也检查了这个,但那里没有回复。

3 个答案:

答案 0 :(得分:2)

尝试从手机中完全卸载应用并重新部署。我刚刚遇到了同样的问题,卸载(包括删除缓存和配置!)为我修复了它。

答案 1 :(得分:0)

您确定在Android Manifest中注册自定义Application类吗?

<application
        android:name=".MyApplication"
...>
.
.
.
</application>

答案 2 :(得分:0)

我有同样的问题。当它出现在您的stacktrace中时,在迭代LinkedList时遇到了java.util.ConcurrentModificationException

at java.util.LinkedList$LinkIterator.next(LinkedList.java:124)

一种解决方案是保护synchronized block or method中的代码。

我选择的另一个解决方案是使用专门用于并发访问的集合。在我的情况下,我想要一个随机访问列表(如ArrayList),所以我使用了Android包 java.util.concurrent.CopyOnWriteArrayList中提供的java.util.concurrent。我没有为LinkedList找到任何并发访问集合,但是CopyOnWriteArrayList可能就足够了。它专门用于阅读很多列表并很少更新。

虽然我不能保证我找到了正确的解决方案(这是一个并发访问问题,所以这很难测试),我没有错误了,我认为我的问题已经解决了。