在使用扩展应用程序的单独类时,应用程序未因Parse.enableLocalDatastore(this)而崩溃

斯拉瓦

当我按照Parse的指导进行操作时,添加Parse.enableLocalDatastore(this)了我的MainActivity onCreate()(带有片段),当我更改设备的方向时,这导致我的应用程序崩溃。

我的logcat:

06-02 12:13:07.036  14407-14407/com.example.android.donotbelateapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.example.android.donotbelateapp, PID: 14407
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.donotbelateapp/com.example.android.donotbelateapp.ui.MainActivity}: java.lang.IllegalStateException: `Parse#enableLocalDatastore(Context)` must be invoked before `Parse#initialize(Context)`

  Caused by: java.lang.IllegalStateException: `Parse#enableLocalDatastore(Context)` must be invoked before `Parse#initialize(Context)`

但是,当我添加一个单独的类扩展Application并在其中放置以下与Parse相关的代码时:

Parse.enableLocalDatastore(this);
Parse.initialize(this, "xxx", "xxx");

问题已解决。

为什么我必须使用这些命令才能使其正常工作?

宜安义

嗯,首先,让我读一下错误:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.android.donotbelateapp/com.example.android.donotbelateapp.ui.MainActivity}: java.lang.IllegalStateException: `Parse#enableLocalDatastore(Context)` must be invoked before `Parse#initialize(Context)`

好的,因此该错误表明必须在Parse.initialize()之前调用Parse.enableLocalDataStore()。

然后,创建一个扩展了Application的类,您明确使用了该类,并在其中调用Parse.enableLocalDataStore()。可能在应用程序生命周期的早期,这意味着它在您的Activity调用Parse.initialize()之前被调用。

因此,您很困惑,当您解决问题时,问题已得到解决。

无论如何,我很想知道什么“解析指导如何在MainActivity中添加Parse.enableLocalDatastore(this)”,所以我转到了该页面,标题为“使用本地数据存储”然后,我实际上通读了它。在第2节“启用本地数据存储”下,它说(强调我):

TodoListApplication也是我们添加解析凭据,设置默认访问控制以及将我们的应用程序设置为使用匿名用户的位置,以便人们无需登录即可在本地保存待办事项。接下来,要启用本地数据存储,只需添加在调用Parse.initialize()之前先调用Parse.enableLocalDatastore()

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章