I'm having trouble casting a class in a class, when I use the inherited class method it gives the following error:
"entity.Aula can not be cast to tableview.AulaTV"
Here is the exception described above.
AulaTV atv = (AulaTV) new Aula().buscarPorCodigo("1ageoB2");
Here are 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;
}
}
Class AulaTV:
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
}