嗨,大家好我是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