我知道有很多人在堆栈溢出时发布此错误但是在这里有所有帮助我无法解决我的问题。
10-23 00:22:15.858 19723-19723/? E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.laiq.laiq/com.laiq.laiq.UI.MainActivity}: java.lang.IllegalStateException: `Parse#enableLocalDatastore(Context)` must be invoked before `Parse#initialize(Context)`
10-23 00:22:15.858 19723-19723/? E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
10-23 00:22:15.858 19723-19723/? E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2442)
10-23 00:22:15.858 19723-19723/? E/AndroidRuntime: at android.app.ActivityThread.access$800(ActivityThread.java:156)
10-23 00:22:15.858 19723-19723/? E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351)
10-23 00:22:15.858 19723-19723/? E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
10-23 00:22:15.858 19723-19723/? E/AndroidRuntime: at android.os.Looper.loop(Looper.java:211)
10-23 00:22:15.858 19723-19723/? E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5373)
10-23 00:22:15.858 19723-19723/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
10-23 00:22:15.858 19723-19723/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
10-23 00:22:15.858 19723-19723/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
10-23 00:22:15.858 19723-19723/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
10-23 00:22:15.858 19723-19723/? E/AndroidRuntime: Caused by: java.lang.IllegalStateException: `Parse#enableLocalDatastore(Context)` must be invoked before `Parse#initialize(Context)`
10-23 00:22:15.858 19723-19723/? E/AndroidRuntime: at com.parse.Parse.enableLocalDatastore(Parse.java:68)
10-23 00:22:15.858 19723-19723/? E/AndroidRuntime: at com.laiq.laiq.UI.MainActivity.onCreate(MainActivity.java:37)
10-23 00:22:15.858 19723-19723/? E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:5990)
10-23 00:22:15.858 19723-19723/? E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
10-23 00:22:15.858 19723-19723/? E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2332)
10-23 00:22:15.858 19723-19723/? E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2442)
10-23 00:22:15.858 19723-19723/? E/AndroidRuntime: at android.app.ActivityThread.access$800(ActivityThread.java:156)
10-23 00:22:15.858 19723-19723/? E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351)
10-23 00:22:15.858 19723-19723/? E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
10-23 00:22:15.858 19723-19723/? E/AndroidRuntime: at android.os.Looper.loop(Looper.java:211)
10-23 00:22:15.858 19723-19723/? E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5373)
10-23 00:22:15.858 19723-19723/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
10-23 00:22:15.858 19723-19723/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
10-23 00:22:15.858 19723-19723/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
10-23 00:22:15.858 19723-19723/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)
我创建了ParseApplication类,但是:
ParseApplication.class
public class ParseApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
ParseCrashReporting.enable(this);
Parse.enableLocalDatastore(this);
Parse.initialize(this, "xxx", "xxx"); --> my keys ofc
}
}
有人有这个问题吗?
应用程序在开始时崩溃。
答案 0 :(得分:0)
您的崩溃报告显示您在第37行的MainActivity中呼叫Parse.enableLocalDatastore(Context)
:
Caused by: java.lang.IllegalStateException: `Parse#enableLocalDatastore(Context)` must be invoked before `Parse#initialize(Context)`
10-23 00:22:15.858 19723-19723/? E/AndroidRuntime: at com.parse.Parse.enableLocalDatastore(Parse.java:68)
10-23 00:22:15.858 19723-19723/? E/AndroidRuntime: at com.laiq.laiq.UI.MainActivity.onCreate(MainActivity.java:37)
所有Parse初始化必须在Application
的扩展名中进行,即在您的情况下ParseApplication
。
假设ParseApplication
已正确添加到您的清单中,您只需删除Parse.*
onCreate()
中的MainActivity
代码。