Boa noite rapaziada.
Meu código está com um erro que eu não consigo tratar aparentemente quando vai adicionar na lista, vejam a linha 20. No console exibe:
Exception in thread "main" java.lang.VerifyError: (class: extras02/Automovel, method: <init> signature: (Ljava/lang/String;Ljava/lang/String;I)V) Constructor must call super() or this()
at extras02.Ex12_arraylist.main(Ex12_arraylist.java:20)
Java Result: 1O que eu fiz:
[code]
/*
*/
package extras02;
import java.text.ParseException;
import java.util.Date;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class Ex12_arraylist {
protected static SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
public static void main(String[] args) {
ArrayList<Automovel> lista = new ArrayList<Automovel>();
try {
lista.add(new Automovel("MODELO1", sdf.parse("15/11/2012")));
lista.add(new Automovel("MODELO2", sdf.parse("05/06/1970")));
lista.add(new Automovel("MODELO3", sdf.parse("18/12/2009")));
} catch (ParseException e) {
}
Ex12_arraylist ex = new Ex12_arraylist();
ArrayList<Automovel> lista2;
try {
lista2 = ex.menosDe10(lista);
for (int i = 0; i < lista2.size(); i++) {
System.out.println(lista2.get(i));
}
} catch (Exception e) {
}
}
private ArrayList<Automovel> menosDe10(ArrayList<Automovel> lista) throws NullPointerException {
ArrayList<Automovel> temp = new ArrayList<Automovel>();
GregorianCalendar gc = new GregorianCalendar();
for (Automovel aux : lista) {
gc.setTime(aux.getAno());
if (gc.get(Calendar.YEAR) >= 2002) {
temp.add(aux);
}
}
return temp;
}
}
class Automovel {
private String modelo;
private Date ano;
public Automovel(String modelo, Date ano) {
this.modelo = modelo;
this.ano = ano;
}
public Date getAno() {
return this.ano;
}
@Override
public String toString() {
return this.modelo + "\n" + Ex12_arraylist.sdf.format(this.ano) + "\n";
}
}
[/code]Alguém sabe o que está errado?
OBS: O exercício exige duas classes no mesmo .java