2
I have the problem to perform a "Cast" in a class, when using the inherited class method of the following error:
"entity. Aula cannot be cast to tableview.Aulatv"
Here gives the exception described above.
AulaTV atv = (AulaTV) new Aula().buscarPorCodigo("1ageoB2");
Follows the classes used:
public class Aula {
private int id;
private String codigo;
private String titulo;
private String conteudo;
private Date dtCadastro;
private String log;
private int serie;
private int disciplina;
private int empresa;
private int cliente;
private File arq;
public Aula() {
}
public Aula(int id, String codigo, String titulo, String conteudo, Date dtCadastro, String log, int serie, int disciplina, int empresa, int cliente, File arq) {
this.id = id;
this.codigo = codigo;
this.titulo = titulo;
this.conteudo = conteudo;
this.dtCadastro = dtCadastro;
this.log = log;
this.serie = serie;
this.disciplina = disciplina;
this.empresa = empresa;
this.cliente = cliente;
this.arq = arq;
}
// gets and sets
public Aula buscaAulaPorCodigo(String codigo) throws Exception {
Aula aula = null;
try {
aula = new AulaDAO().buscarPorCodigo(codigo);
} catch (Exception e) {
System.out.println(e.getMessage());
throw new Exception(e.getLocalizedMessage());
}
return aula;
}
public static Aula buscaNoListPorNome(List<Aula> list, String chave) {
for (Aula a : list) {
if (a.getCodigo().equalsIgnoreCase(chave)) {
return a;
}
}
return null;
}
}
Aulatv class:
public class AulaTV extends Aula {
private CheckBox checkBox;
public AulaTV() {
super();
checkBox = new CheckBox();
}
public AulaTV(CheckBox checkBox, int id, String codigo, String titulo, String conteudo, Date dtCadastro, String log, int serie, int disciplina, int empresa, int cliente, File arq) {
super(id, codigo, titulo, conteudo, dtCadastro, log, serie, disciplina, empresa, cliente, arq);
this.checkBox = checkBox;
}
// gets and sets
}
Abbreviate that code, that pile of get and set are unnecessary to understand the problem...
– Jéf Bueno