应用未运行时,应用在解析推送通知时崩溃

时间:2015-08-18 14:51:43

标签: java android parse-platform

当我打开我的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:致命异常:   主要       处理:com.myatminsoe.mkeyboard,PID:24406       java.lang.RuntimeException:无法创建服务com.parse.PushService:java.lang.NullPointerException:Attempt to   调用虚方法'android.content.Context   在null对象上的com.parse.ParsePlugins $ Android.applicationContext()'   参考               在android.app.ActivityThread.handleCreateService(ActivityThread.java:2771)               在android.app.ActivityThread.access $ 1800(ActivityThread.java:151)               在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1386)               在android.os.Handler.dispatchMessage(Handler.java:102)               在android.os.Looper.loop(Looper.java:135)               在android.app.ActivityThread.main(ActivityThread.java:5254)               at java.lang.reflect.Method.invoke(Native Method)               在java.lang.reflect.Method.invoke(Method.java:372)               在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:903)               在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)        引起:java.lang.NullPointerException:尝试调用虚方法'android.content.Context   在null对象上的com.parse.ParsePlugins $ Android.applicationContext()'   参考               在com.parse.PushService.onCreate(PushService.java:238)               在android.app.ActivityThread.handleCreateService(ActivityThread.java:2761)   在android.app.ActivityThread.access $ 1800(ActivityThread.java:151)   在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1386)   在android.os.Handler.dispatchMessage(Handler.java:102)   在android.os.Looper.loop(Looper.java:135)   在android.app.ActivityThread.main(ActivityThread.java:5254)   at java.lang.reflect.Method.invoke(Native Method)   在java.lang.reflect.Method.invoke(Method.java:372)   在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:903)   在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

1 个答案:

答案 0 :(得分:1)

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

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