gpt4 book ai didi

java - 当应用程序未运行时,应用程序在解析推送通知时崩溃

转载 作者:行者123 更新时间:2023-11-30 01:56:57 24 4
gpt4 key购买 nike

当我打开我的 Android 应用程序并测试解析推送通知时,它可以正常工作。但是,当我从多任务处理中终止我的应用程序并再次测试时,应用程序崩溃了。

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Parse.initialize(MainActivity.this, "cMm2mJvkRlIButQ0wM4lfj5veFxrQYUKw8P4mdM4", "bOplHPHvWb9IRzv2EbQnylWFgyveTsDYEspV2qs0");
ParseAnalytics.trackAppOpenedInBackground(getIntent());
ParsePush.subscribeInBackground("", new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
} else {
Log.e("com.parse.push", "failed to subscribe for push", e);
}
}
});
}

错误日志

08-18 21:16:21.694 24406-24406/? E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.myatminsoe.mkeyboard, PID: 24406 java.lang.RuntimeException: Unable to create service com.parse.PushService: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context com.parse.ParsePlugins$Android.applicationContext()' on a null object reference at android.app.ActivityThread.handleCreateService(ActivityThread.java:2771) at android.app.ActivityThread.access$1800(ActivityThread.java:151) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1386) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context com.parse.ParsePlugins$Android.applicationContext()' on a null object reference at com.parse.PushService.onCreate(PushService.java:238) at android.app.ActivityThread.handleCreateService(ActivityThread.java:2761)             at android.app.ActivityThread.access$1800(ActivityThread.java:151)             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1386)             at android.os.Handler.dispatchMessage(Handler.java:102)             at android.os.Looper.loop(Looper.java:135)             at android.app.ActivityThread.main(ActivityThread.java:5254)             at java.lang.reflect.Method.invoke(Native Method)             at java.lang.reflect.Method.invoke(Method.java:372)             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

最佳答案

在 Application onCreate 中进行解析初始化,并确保在主线程中调用它。

Parse.initialize(new Parse.Configuration.Builder(getApplicationContext()).applicationId(
...).build());

关于java - 当应用程序未运行时,应用程序在解析推送通知时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32075789/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com