I get a lot of messages from users about the failure of my application. The persistent error seems to be related to my initialization of parse.com, however I configured it as described in the parsing guide.
here is the stack trace:
java.lang.RuntimeException: Unable to start receiver com.parse.ParseBroadcastReceiver: java.lang.RuntimeException: applicationContext is null. You must call Parse.initialize(context, applicationId, clientKey) before using the Parse library. at android.app.ActivityThread.handleReceiver(ActivityThread.java:2580) at android.app.ActivityThread.access$1700(ActivityThread.java:151) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397) at android.os.Handler.dispatchMessage(Handler.java:110) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:5292) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640) 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:606) at com.parse.Parse.getApplicationContext(Parse.java:214) at com.parse.ManifestInfo.getContext(ManifestInfo.java:322) at com.parse.ManifestInfo.getPackageManager(ManifestInfo.java:330) at com.parse.ManifestInfo.getPackageInfo(ManifestInfo.java:356) at com.parse.ManifestInfo.deviceSupportsGcm(ManifestInfo.java:441) at com.parse.ManifestInfo.getPushType(ManifestInfo.java:210) at com.parse.PushService.startServiceIfRequired(PushService.java:168) at com.parse.ParseBroadcastReceiver.onReceive(ParseBroadcastReceiver.java:19) at android.app.ActivityThread.handleReceiver(ActivityThread.java:2573) ... 10 more
and here is my initialization code:
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home_screen); Parse.initialize(this, "hGG5RdgNVdI7eCeZynV32lWYXywQRHkpp5zLdY7Q", "TwmNbpBYEt4u3euE3lzNIgwyroSl8RPGF2dJFsPv"); ParseInstallation.getCurrentInstallation().saveInBackground();
Can anyone understand what causes this error, and how to fix it?
below is the code of my receiver:
public static class Receiver extends ParsePushBroadcastReceiver { private String notificationText; private Boolean notificationreceived = false; public Receiver(){ } private static final String TAG = "MyNotificationsReceiver"; @Override public void onPushOpen(Context context, Intent intent) { Log.e("Push", "Clicked"); Intent i = new Intent(context, HomeScreen.class); notificationreceived = true; i.putExtra("alert",notificationText); i.putExtra("alertreceived", notificationreceived); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); Scb998.scb988b=true; try { JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data")); Scb998.msg = json.getString("alert"); } catch (JSONException e) { Log.d(TAG, "JSONException: " + e.getMessage()); } } }
source share