原谅我,但我无法调用 NotificationBuilder 的 notify() 方法。我有这个代码:
timer.scheduleAtFixedRate(
new TimerTask() {
@Override
public void run() {
synchronized (this) {
Builder notif = new NotificationCompat.Builder(c);
notif.setContentIntent(contIntent)
.setWhen(System.currentTimeMillis())
.setTicker("Notification ticker")
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Vinceri")
.setContentText("Ha recibido una oferta de trabajo")
.setAutoCancel(true);
notif.notify();
}
}
}
而且无论我把同步块放在哪里,我都会得到同样的异常:
04-05 10:42:55.116: E/AndroidRuntime(18244): FATAL EXCEPTION: Timer-0
04-05 10:42:55.116: E/AndroidRuntime(18244): java.lang.IllegalMonitorStateException: object not locked by thread before notifyAll()
04-05 10:42:55.116: E/AndroidRuntime(18244): at java.lang.Object.notifyAll(Native Method)
04-05 10:42:55.116: E/AndroidRuntime(18244): at com.publidirecta.vinceriazafata.NotificationService$1.run(NotificationService.java:126)
04-05 10:42:55.116: E/AndroidRuntime(18244): at java.util.Timer$TimerImpl.run(Timer.java:284)
这可能是一个菜鸟问题,但是......我必须做些什么才能不收到那个例外?谢谢你。