嗨,大家好我是Android的開始,我試圖從與我的主要活動不同的類發出通知。但e.printStackTrace()聲明爲「null」,並停在行:「NotificationManager notificationManager =(NotificationManager)getSystemService(NOTIFICATION_SERVICE);」如果我從mainActivity發出同樣的通知一切順利。你能幫我嗎?當我嘗試通知某些事件時發生空錯誤
if(giorni_di_differenza <= 15)
{
try{
PendingIntent pi = PendingIntent.getActivity(context, 0, new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS), 0);
NotificationCompat.Builder n = new NotificationCompat.Builder(context)
.setContentTitle(nome_evento)
.setContentText(descrizione_evento)
.setContentIntent(pi)
.setAutoCancel(true)
.setLights(Color.GREEN, 1000, 1000)
.setSmallIcon(R.drawable.ic_launcher);
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, n.build());
}catch(Exception e){
e.printStackTrace();
}
}
如果您需要更多代碼,我可以寄給您。
的logcat:http://pastebin.com/W4hKbf6W(暫停GC錯誤是錯誤的,由於三星股票ROM)
發佈完整日誌。 – 2014-10-31 11:13:56
好吧,一秒@kalyanpvs – 2014-10-31 11:14:26