Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Implementing Designs for Android Adding Push Notifications from Parse.com Setting Up Push Notifications

Gilad Solter
Gilad Solter
2,986 Points

App crashed when push sent

Hi, I followed the instructions on parse.com for setting up the push notifications (three times...). But when I try to send a push notification the app crashes. This happened on an emulator and on a real device.

Any suggestions?

10 Answers

Daniel Schmidt
Daniel Schmidt
1,683 Points

See my answer in this thread. Might be your problem as well (Parse version 1.7 has different push behaviour).

william parrish
william parrish
13,774 Points

Could be a bunch of different things, and here is what we need to do to find out.

Go to your logcat, and make sure you have it at least set for debug, if not verbose.
Run the app again, and initiate the workflow needed to generate the push message. The app will crash, but what we are most interested in is the string of error messages ( mine are in red, yours may be set up different ) that happen right at the end.

Post the whole chunk of them here, and i will help you figure it out. This simple step is probably one of the most important things to get comfortable doing, as you make changes and eventually end up breaking things. Logcat will almost always give you good information on why it stopped working, and the specific activity, class, and or line number where the problem started.

Gilad Solter
Gilad Solter
2,986 Points

That's the log:

10-07 19:57:30.685 1104-1104/com.simplife.ribbit D/dalvikvm﹕ Late-enabling CheckJNI 10-07 19:57:30.729 1104-1104/com.simplife.ribbit E/Trace﹕ error opening trace file: No such file or directory (2) 10-07 19:57:31.069 1104-1107/com.simplife.ribbit D/dalvikvm﹕ GC_CONCURRENT freed 259K, 14% free 2497K/2880K, paused 0ms+0ms, total 3ms 10-07 19:57:31.233 1104-1104/com.simplife.ribbit D/AndroidRuntime﹕ Shutting down VM 10-07 19:57:31.233 1104-1104/com.simplife.ribbit W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa61a8908) 10-07 19:57:31.233 1104-1104/com.simplife.ribbit E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start receiver com.parse.ParsePushBroadcastReceiver: java.lang.NullPointerException at android.app.ActivityThread.handleReceiver(ActivityThread.java:2383) at android.app.ActivityThread.access$1500(ActivityThread.java:141) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1310) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5041) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NullPointerException at com.parse.ParsePushBroadcastReceiver.getSmallIconId(ParsePushBroadcastReceiver.java:253) at com.parse.ParsePushBroadcastReceiver.getNotification(ParsePushBroadcastReceiver.java:335) at com.parse.ParsePushBroadcastReceiver.onPushReceive(ParsePushBroadcastReceiver.java:143) at com.parse.ParsePushBroadcastReceiver.onReceive(ParsePushBroadcastReceiver.java:104) at android.app.ActivityThread.handleReceiver(ActivityThread.java:2376)             at android.app.ActivityThread.access$1500(ActivityThread.java:141)             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1310)             at android.os.Handler.dispatchMessage(Handler.java:99)             at android.os.Looper.loop(Looper.java:137)             at android.app.ActivityThread.main(ActivityThread.java:5041)             at java.lang.reflect.Method.invokeNative(Native Method)             at java.lang.reflect.Method.invoke(Method.java:511)             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)             at dalvik.system.NativeStart.main(Native Method) 10-07 19:57:45.989 1166-1166/com.simplife.ribbit E/Trace﹕ error opening trace file: No such file or directory (2)

william parrish
william parrish
13,774 Points

Cool, it looks like you are running into null pointer exceptions, when parse tries to execute some of its built in methods.

Can you copy and paste your entire AndroidManifest.xml?

william parrish
william parrish
13,774 Points

And if you could, also paste the contents of the class you use to initialize your parse api key, and set the installations and callbacks. If you havent changed the names, it should be called ribbitapplication.

Gilad Solter
Gilad Solter
2,986 Points

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.simplife.ribbit">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<uses-feature
    android:name="android.hardware.camera"
    android:required="true"/>

<permission android:protectionLevel="signature"
    android:name="com.simplife.ribbit.permission.C2D_MESSAGE" />
<uses-permission android:name="com.simplife.ribbit.permission.C2D_MESSAGE" />

<application
    android:name=".RibbitApplication"
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/Theme.Ribbit">
    <activity
        android:name=".ui.MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".ui.LoginActivity"
        android:label="@string/title_activity_login"
        android:screenOrientation="portrait"></activity>
    <activity
        android:name=".ui.SignUpActivity"
        android:label="@string/title_activity_sign_up"
        android:parentActivityName=".ui.LoginActivity"
        android:screenOrientation="portrait"></activity>
    <activity
        android:name=".ui.EditFriendsActivity"
        android:label="@string/title_activity_edit_friends"
        android:parentActivityName=".ui.MainActivity"
        android:screenOrientation="portrait">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.simplife.ribbit.MainActivity" />
    </activity>
    <activity
        android:name=".ui.RecipientsActivity"
        android:label="@string/title_activity_recipients"
        android:parentActivityName=".ui.MainActivity"
        android:screenOrientation="portrait">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.simplife.ribbit.MainActivity" />
    </activity>
    <activity
        android:name=".ui.ViewImageActivity"
        android:label="@string/title_activity_view_image"
        android:parentActivityName=".ui.MainActivity"
        android:screenOrientation="portrait">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.simplife.ribbit.MainActivity" />
    </activity>


    <service android:name="com.parse.PushService" />
    <receiver android:name="com.parse.ParseBroadcastReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.USER_PRESENT" />
        </intent-filter>
    </receiver>
    <receiver android:name="com.parse.ParsePushBroadcastReceiver"
        android:exported="false">
        <intent-filter>
            <action android:name="com.parse.push.intent.RECEIVE" />
            <action android:name="com.parse.push.intent.DELETE" />
            <action android:name="com.parse.push.intent.OPEN" />
        </intent-filter>
    </receiver>
    <receiver android:name="com.parse.GcmBroadcastReceiver"
        android:permission="com.google.android.c2dm.permission.SEND">
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

            <category android:name="com.simplife.ribbit" />
        </intent-filter>
    </receiver>

</application>

</manifest>

Gilad Solter
Gilad Solter
2,986 Points

package com.simplife.ribbit;

import android.app.Application;

import com.parse.Parse; import com.parse.ParseInstallation; import com.parse.ParseAnalytics; import com.parse.ParseUser; import com.parse.PushService; import com.simplife.ribbit.utils.ParseConstants;

public class RibbitApplication extends Application{

@Override
public void onCreate() {
    super.onCreate();
    Parse.initialize(this, "IQnnlqXG4hQ9uGMDR0M02iZeIQi8rnwYabmTEA7q", "DqGP7KoW6IkKawCfuuzh2Oy4UGsUppG9XGdBr1Lt");
    ParseInstallation.getCurrentInstallation().saveInBackground();
}


public static void updateParseInstallation(ParseUser user) {
    ParseInstallation installation = ParseInstallation.getCurrentInstallation();
    installation.put(ParseConstants.KEY_USER_ID, user.getObjectId());
    installation.saveInBackground();
}

}

william parrish
william parrish
13,774 Points

In onCreate, you are missing the part where you setup the necessary callback for the PushService.

Right after you initialize Parse and before your firstcall to .getCurrentInstallation() type in :

PushService.setDefaultPushCallback(this, MainActivity.class)

Try that, see what happens

william parrish
william parrish
13,774 Points

That callback is responsible for the handling of the Pushnotification, and Parse will look for what you define there, and when it tries to handle the push notification.

Gilad Solter
Gilad Solter
2,986 Points

No, still crashes...

BTW thanks for the help!

william parrish
william parrish
13,774 Points

You using Github or anything like that? So i can see all your class files?

Gilad Solter
Gilad Solter
2,986 Points

no, i don't, sorry. I can paste the code here though... which class do you need to see??