Ido Naveh
Ido Naveh

Reputation: 2492

app opens a crash dialog on device startup

Every time when I open my device I see this message:

Link for the image (I don't have enough reputation): https://i.sstatic.net/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:

Parse.initialize(this, "Application ID", "Client Key");
    ParseInstallation installation = ParseInstallation.getCurrentInstallation();
    installation.saveInBackground();

It pops every time that I open my device... what to do?

Upvotes: 1

Views: 2313

Answers (3)

Nirmal Raj
Nirmal Raj

Reputation: 729

I too had a similar error message.

I believe that one can initialise parse using

Parse.initialize(this, "PARSE_APPLICATION_ID", "PARSE_CLIENT_KEY");

only once in a whole app.i.e you cannot initialise parse again and again in each activity or fragment. I recommend initialising parse in the main activity and do not repeat the initialise code anywhere else.

Upvotes: 0

Hookah_Smoka
Hookah_Smoka

Reputation: 374

It seems like you're using Parse. If so, you have to make sure to set it up right before you can use it in your app. Make sure you've followed all the steps documented in the QuickStart guide from Parse. As the error message informs you that you haven't called the initiaze method of Parse, make sure you do this in your Application subclass that you have to create by yourself:

Parse.initialize(this, "APPLICATION ID", "CLIENT KEY");

After you did this, you can test Parse to check if everything is configured as it should with the Test the SDK section at the bottom of the QuickStart guide.

Upvotes: 0

Carnal
Carnal

Reputation: 22064

You should call this in your Application class, in order just do it once.

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");
  }
}

In the Manifest declare it like this

<application
    android:name="yourpackagename.YourApplicationName"
.
.
.

Or if you want to use your approach and call it in every Activity, you will have to use getApplicationContext() instead of this.

Upvotes: 9

Related Questions