Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android studio 不幸的是,应用程序已停止发送通知时出错_Android Studio_Database Connection - Fatal编程技术网

Android studio 不幸的是,应用程序已停止发送通知时出错

Android studio 不幸的是,应用程序已停止发送通知时出错,android-studio,database-connection,Android Studio,Database Connection,发送通知时,我没有将消息作为通知收到,我的应用程序显示: 不幸的是,应用程序已停止 在调试过程中,我得到了message=null,应用程序给出了错误。您需要检查消息是否不等于null import android.app.NotificationManager; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.support.v4.co

发送通知时,我没有将消息作为通知收到,我的应用程序显示:

不幸的是,应用程序已停止


在调试过程中,我得到了
message=null
,应用程序给出了错误。

您需要检查消息是否不等于null

import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;

import com.google.android.gms.gcm.GcmListenerService;
import com.htl.jsfshoppingfestival.DataBaseHandler;

public class MyGcmListenerService extends GcmListenerService {

    private static final String TAG = "MyGcmListenerService";
    private NotificationManager mNotificationManager;
    Context ctx;
    int countNotification=0;

    public void onMessageReceived(String from, Bundle data) {
        String message = data.getString("Message");
        Log.d(TAG, "From: " + from);
        Log.d(TAG, "Message: " + message);

      //  Toast.makeText(getApplicationContext(), "Notification :"+message, Toast.LENGTH_LONG).show();

      //  Toast.makeText(getApplicationContext(),from+message,Toast.LENGTH_LONG).show();    

        if (from.startsWith("/topics/")) {
            // message received from some topic.
        } else {
            // normal downstream message.
        }

        // [START_EXCLUDE]
        /**
         * Production applications would usually process the message here.
         * Eg: - Syncing with server.
         *     - Store message in local database.
         *     - Update UI.
         */

        /**
         * In some cases it may be useful to show a notification indicating to the user
         * that a message was received.
         */
        sendNotification(message);

        // [END_EXCLUDE]
    }
    // [END receive_message]

    /**
     * Create and show a simple notification containing the received GCM message.
     *
     * @param message GCM message received.
     */
    private void sendNotification(String message) {

        DataBaseHandler db = new DataBaseHandler(this);
        db.addMessage(message);
        countNotification=db.getRowCount();
        db.close();

        Log.d("sender", "Broadcasting message");
        Intent localIntent = new Intent("badge count");
        // You can also include some extra data.
        localIntent.putExtra("Count", countNotification);
        LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent);
}
}    

你在哪个街区得到空值?OnMessageReceived或SendNotification?

OnMessageReceived那么肯定没有任何东西进入
捆绑包
,请检查onec,该链接可能会帮助您调试我得到:->捆绑包[{subtitle=,google.sent_time=1475053305940,msgcnt=1,title=new,振动=1,google.message_id=0:1475053305948338%64ae29a2f9fd7ecd,message=new offers,collapse_key=do_not_collapse,tickerText=}@SiddharthSahni您能正确格式化
包吗。
if(message != null && !message.trim().isEmpty())
{
     sendNotification(message);
}