Erro

1 resposta
A

alguém sabe me dizer q erro é esse…
Exception in thread “AWT-EventQueue-0” java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String

eu acho q o erro está aqui mas naum consegui consertar ainda…

for (Iterator it = listaIds.iterator(); it.hasNext()<img src="https://cdn.jsdelivr.net/gh/twitter/twemoji@14/assets/72x72/w.pngink.png?v=9" title=":wink:" class="emoji" alt=":wink:"> {

String elem = it.next();

lista.add((Usuario) em.createNamedQuery(“Usuario.findById”).setParameter(“id”, elem).getSingleResult());

estou buscando umas String mas no banco o id é do tipo integer…

1 Resposta

fiaux

Você já respondeu…

Veja:

public class ClassCastException
extends RuntimeException

Thrown to indicate that the code has attempted to cast an object to a subclass of which it is not an instance. For example, the following code generates a ClassCastException:

Object x = new Integer(0);
     System.out.println((String)x);
 </blockquote>

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ClassCastException.html

Criado 3 de novembro de 2008
Ultima resposta 3 de nov. de 2008
Respostas 1
Participantes 2