每次打开设备时,我都会看到此消息:
图片的链接(我没有足够的声誉):http://i.stack.imgur.com/TceMS.png
logcat的:
12-19 11:57:47.914: E/com.parse.PushService(18423): The Parse push service cannot start because Parse.initialize has not yet been called. If you call Parse.initialize from an Activity's onCreate, that call should instead be in the Application.onCreate. Be sure your Application class is registered in your AndroidManifest.xml with the android:name property of your <application> tag.
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start service com.parse.PushService@419934e8 with Intent { act=com.google.android.c2dm.intent.REGISTRATION flg=0x10 pkg=com.idonaveh.guess cmp=com.idonaveh.guess/com.parse.PushService (has extras) }: java.lang.RuntimeException: applicationContext is null. You must call Parse.initialize(context, applicationId, clientKey) before using the Parse library.
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2859)
at android.app.ActivityThread.access$1900(ActivityThread.java:162)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1461)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5371)
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:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: applicationContext is null. You must call Parse.initialize(context, applicationId, clientKey) before using the Parse library.
at com.parse.Parse.checkContext(Parse.java:634)
at com.parse.Parse.getApplicationContext(Parse.java:236)
at com.parse.ManifestInfo.getContext(ManifestInfo.java:322)
at com.parse.ManifestInfo.getPackageName(ManifestInfo.java:326)
at com.parse.ManifestInfo.getIntentReceivers(ManifestInfo.java:131)
at com.parse.ManifestInfo.hasIntentReceiver(ManifestInfo.java:123)
at com.parse.ManifestInfo.getPushUsesBroadcastReceivers(ManifestInfo.java:174)
at com.parse.PushService.wipeRoutingAndUpgradePushStateIfNeeded(PushService.java:449)
at com.parse.PushService.onStartCommand(PushService.java:430)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2842)
... 10 more
解析初始化:
Parse.initialize(this, "Application ID", "Client Key");
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.saveInBackground();
每次打开设备时都会弹出......怎么办?
答案 0 :(得分:9)
您应该在Application
课程中调用此方法,只需执行一次。
import com.parse.Parse;
import android.app.Application;
public class YourApplicationName extends Application {
@Override
public void onCreate() {
super.onCreate();
Parse.enableLocalDatastore(this);
Parse.initialize(this, "PARSE_APPLICATION_ID", "PARSE_CLIENT_KEY");
}
}
在Manifest中声明它就像这样
<application
android:name="yourpackagename.YourApplicationName"
.
.
.
或者,如果您想使用自己的方法并在每个Activity
中调用它,则必须使用getApplicationContext()
代替this
。
答案 1 :(得分:0)
好像你正在使用Parse。 如果是这样,您必须确保在应用程序中使用它之前进行设置。 确保您已遵循Parse QuickStart guide中记录的所有步骤。 由于错误消息通知您尚未调用Parse的initiaze方法,请确保在您必须自己创建的Application子类中执行此操作:
Parse.initialize(this, "APPLICATION ID", "CLIENT KEY");
执行此操作后,您可以使用快速入门指南底部的测试SDK部分测试Parse以检查是否所有内容都已配置完毕。
答案 2 :(得分:0)
我也有类似的错误消息。
我相信可以使用
初始化解析Parse.initialize(this,“PARSE_APPLICATION_ID”,“PARSE_CLIENT_KEY”);
在整个应用程序中只有一次。你不能在每个活动或片段中反复初始化解析。 我建议在主活动中初始化解析,不要在其他任何地方重复初始化代码。