4
I’m making an Android application and I’m having a question while generating a notification.
Here I will be providing an excerpt of the code:
public void gerarNotificacao(View view) {
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
SimpleDateFormat datas = new SimpleDateFormat("dd/mm/yyyy");
mDiasdaSem = String.valueOf(datas.format(new Date()));
eventoDao = new eventosDao(this);
eventoDao.open();
String filtro = mDiasdaSem;
List<Eventos> eventos = eventoDao.listarEventos(filtro);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setTicker("Ticker Texto");
builder.setTicker( (CharSequence) eventos);
builder.setSmallIcon(R.drawable.ic_launcher);
Notification n = builder.build();
n.vibrate = new long[]{250, 300, 150, 600};
nm.notify(R.drawable.ic_launcher, n);
try
{
Uri som = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone toque = RingtoneManager.getRingtone(this, som);
toque.play();
}
catch(Exception e)
{
}
}
The following error occurs:
java.util.Arraylist cannot be cast to java.lang.Charsequence
How to solve?
@Otavio the error occurs because you are not passing the correct type to the method
setTicker()
. You can’t make acast
of aArrayList<>
for aCharSequence
. Post your Event class code as well.– Luídne
Well, I don’t see any
ArrayList<>
!– viana