致:java.lang.IllegalStateException:ParsePlugins已初始化 [英] Caused by: java.lang.IllegalStateException: ParsePlugins is already initialized

查看:273
本文介绍了致:java.lang.IllegalStateException:ParsePlugins已初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我退出程序,重新启动它,我得到一个例外。

I quit the app, relaunch it, I am getting an exception.

public void onCreate() {
-->here Parse.initialize(this, "adfsfasdfs",
            "asdfadfsdf");
    ParseInstallation.getCurrentInstallation().saveInBackground();
    ParseInstallation.create(identity == null ? "No Identity Set"
            : identity);

异常

07-08 23:27:29.411: E/AndroidRuntime(4889): Caused by: java.lang.IllegalStateException: ParsePlugins is already initialized
07-08 23:27:29.411: E/AndroidRuntime(4889):     at com.parse.ParsePlugins.set(ParsePlugins.java:27)
07-08 23:27:29.411: E/AndroidRuntime(4889):     at com.parse.ParsePlugins.access$200(ParsePlugins.java:11)
07-08 23:27:29.411: E/AndroidRuntime(4889):     at com.parse.ParsePlugins$Android.initialize(ParsePlugins.java:141)
07-08 23:27:29.411: E/AndroidRuntime(4889):     at com.parse.Parse.initialize(Parse.java:178)
07-08 23:27:29.411: E/AndroidRuntime(4889):     at com.mcruiseon.caregiri.Registration.onCreate(Registration.java:98)

清单文件

        <service android:name="com.parse.PushService" />

        <receiver android:name="com.parse.ParseBroadcastReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.USER_PRESENT" />
            </intent-filter>
        </receiver>
        <receiver
            android:name="com.parse.ParsePushBroadcastReceiver"
            android:exported="false" >
            <intent-filter>
                <action android:name="com.parse.push.intent.RECEIVE" />
                <action android:name="com.parse.push.intent.DELETE" />
                <action android:name="com.parse.push.intent.OPEN" />
            </intent-filter>
        </receiver>

编辑:

我不知道为什么解析会抛出异常这一点。为什么不直接信息,继续前进。它的初始化,所以大问题,如果我再次初始化它。

I wonder why Parse would throw an exception for this. Why not just info and move on. Its initialized, so big deal if I initialized it again.

解决方案

我已在解析放弃。不喜欢的应用程序的方式,只是为了刺激来维持。

I have given up on Parse. Dont like the Application way, just to irritating to maintain.

推荐答案

Parse.initialize()只应调用的一次,整个应用程序

Parse.initialize() should only be called once for an entire application.

调用它的活动的onCreate 功能可能会导致它被初始化一次以上,如的活动可以在应用程序的生命周期的过程中创造了超过一次。

Calling it in an Activity's onCreate function can cause it to be initialized more than once, as an Activity can be created more than once during an app's lifecycle.

相反,创建一个应用程序类(并添加安卓名称属性的应用程序的清单)。

Instead, create an Application class (and add an android:name attribute to your your application's manifest).

应用程序:(注意不是活动/服务/ Reciever)

//Note that this is an android.app.Application class.
public class MyApplication extends android.app.Application {

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

    //This will only be called once in your app's entire lifecycle.
    Parse.initialize(this,
            getResources().getString(R.string.parse_application_id),
            getResources().getString(R.string.parse_client_key));
}

AndroidManifest:

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

这篇关于致:java.lang.IllegalStateException:ParsePlugins已初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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