Olá galera... estou utilizando um Vector aqui em minha aplicação... mas estou tendo um problema muito chato com nullPointerException...
Estou gerando um relatório... e quando crio um vector do tipo relatório para receber os dados ele está dando nullPointerException no meu Vector Relatorios...
ae está o código pessoal:
if (comando.equals("btnGerarRel")){
try{
JOptionPane.showMessageDialog(null,"DDDD");
Vector<Clientes>v;
Vector <Relatorios> v2=null;
Clientes c = new Clientes();
c.setMatricula(telaRelatorio.getMatricula());
c = dao.consultar(c);
String consulta = null;
int nivel = Integer.parseInt(c.getNivel());
switch (nivel){
case 1:{
consulta = "select * from matrizes where nummatriz=? OR nummatriz like '#%' ORDER BY nummatriz";
consulta = consulta.replaceFirst("#",c.getNumMatriz()+".");
break;
}
case 2:{
consulta = "select * from matrizesmortasn2 where nummatriz=? OR nummatriz like '#%' ORDER BY nummatriz";
consulta = consulta.replaceFirst("#",c.getNumMatriz()+".");
break;
}
case 3:{
consulta = "select * from matrizesmortasn3 where nummatriz=? OR nummatriz like '#%' ORDER BY nummatriz";
consulta = consulta.replaceFirst("#",c.getNumMatriz()+".");
break;
}
case 4:{
consulta = "select * from matrizesmortasn4 where nummatriz=? OR nummatriz like '#%' ORDER BY nummatriz";
consulta = consulta.replaceFirst("#",c.getNumMatriz()+".");
break;
}
case 5:{
consulta = "select * from matrizesmortasn5 where nummatriz=? OR nummatriz like '#%' ORDER BY nummatriz";
consulta = consulta.replaceFirst("#",c.getNumMatriz()+".");
break;
}
case 6:{
consulta = "select * from matrizesmortasn6 where nummatriz=? OR nummatriz like '#%' ORDER BY nummatriz";
consulta = consulta.replaceFirst("#",c.getNumMatriz()+".");
break;
}
case 7:{
consulta = "select * from matrizesmortasn7 where nummatriz=? OR nummatriz like '#%' ORDER BY nummatriz";
consulta = consulta.replaceFirst("#",c.getNumMatriz()+".");
break;
}
case 8:{
consulta = "select * from matrizesmortasn8 where nummatriz=? OR nummatriz like '#%' ORDER BY nummatriz";
consulta = consulta.replaceFirst("#",c.getNumMatriz()+".");
break;
}
case 9:{
consulta = "select * from matrizesmortasn9 where nummatriz=? OR nummatriz like '#%' ORDER BY nummatriz";
consulta = consulta.replaceFirst("#",c.getNumMatriz()+".");
break;
}
case 10:{
consulta = "select * from matrizesmortasn10 where nummatriz=? OR nummatriz like '#%' ORDER BY nummatriz";
consulta = consulta.replaceFirst("#",c.getNumMatriz()+".");
break;
}
case 11:{
consulta = "select * from matrizesmortasn11 where nummatriz=? OR nummatriz like '#%' ORDER BY nummatriz";
consulta = consulta.replaceFirst("#",c.getNumMatriz()+".");
break;
}
case 12:{
consulta = "select * from matrizesmortasn12 where nummatriz=? OR nummatriz like '#%' ORDER BY nummatriz";
consulta = consulta.replaceFirst("#",c.getNumMatriz()+".");
break;
}
case 13:{
consulta = "select * from matrizesmortasn13 where nummatriz=? OR nummatriz like '#%' ORDER BY nummatriz";
consulta = consulta.replaceFirst("#",c.getNumMatriz()+".");
break;
}
case 14:{
consulta = "select * from matrizesmortasn14 where nummatriz=? OR nummatriz like '#%' ORDER BY nummatriz";
consulta = consulta.replaceFirst("#",c.getNumMatriz()+".");
break;
}
case 15:{
consulta = "select * from matrizesmortasn15 where nummatriz=? OR nummatriz like '#%' ORDER BY nummatriz";
consulta = consulta.replaceFirst("#",c.getNumMatriz()+".");
break;
}
case 16:{
consulta = "select * from matrizesmortasn16 where nummatriz=? OR nummatriz like '#%' ORDER BY nummatriz";
consulta = consulta.replaceFirst("#",c.getNumMatriz()+".");
break;
}
case 17:{
consulta = "select * from matrizesmortasn17 where nummatriz=? OR nummatriz like '#%' ORDER BY nummatriz";
consulta = consulta.replaceFirst("#",c.getNumMatriz()+".");
break;
}
case 18:{
consulta = "select * from matrizesmortasn18 where nummatriz=? OR nummatriz like '#%' ORDER BY nummatriz";
consulta = consulta.replaceFirst("#",c.getNumMatriz()+".");
break;
}
} // fim do switch
v = dao.consultarNumMatriz(c,consulta);
Relatorios relatorios = new Relatorios();
int tam = v.size();
int contFilhos = 0;
int contNetos=0;
int contBisnetos1 =0;
int contBisnetos2 =0;
int contBisnetos3 =0;
int contBisnetos4 =0;
String guardaNomeF1 = null;
String guardaNomeF2 = null;
String guardaNomeN1 = null;
String guardaNomeN2 = null;
String guardaNomeN3 = null;
String guardaNomeN4 = null;
for(int i =0; i<tam;i++){
if(v.get(i).getGrauNaMatriz().equals("PAI")){
relatorios.setNomePai(v.get(i).getNome());
relatorios.setCpfPai(v.get(i).getCpf());
}
else
/*Coloquei um contador de filhos...
* Se já for o segundo filho eu adiciono um no contador e o próximo será o segundo
* então eu o coloca na segunda posição do relatório
*/
if(contFilhos==0){
if(v.get(i).getGrauNaMatriz().equals("FILHO")){
relatorios.setNomeF1(v.get(i).getNome());
relatorios.setCpfF1(v.get(i).getCpf());
contFilhos =1;
guardaNomeF1 = v.get(i).getNome();
}
} // fim do ifContFilhos
else
if(contFilhos==1){
relatorios.setNomeF2(v.get(i).getNome());
relatorios.setCpfF2(v.get(i).getCpf());
guardaNomeF2 = v.get(i).getNome();
}
if((v.get(i).getGrauNaMatriz().equals("NETO")) && (v.get(i).getIndicador().equals(guardaNomeF1))){
if(contNetos==0){
relatorios.setNomeN1(v.get(i).getNome());
relatorios.setCpfN1(v.get(i).getCpf());
contNetos=1;
guardaNomeN1 = v.get(i).getNome();
}
else
if(contNetos==1){
relatorios.setNomeN2(v.get(i).getNome());
relatorios.setCpfN2(v.get(i).getCpf());
contNetos=2;
guardaNomeN2 = v.get(i).getNome();
}
}
if((v.get(i).getGrauNaMatriz().equals("NETO")) && (v.get(i).getIndicador().equals(guardaNomeF2))){
if(contNetos==0){
relatorios.setNomeN3(v.get(i).getNome());
relatorios.setCpfN3(v.get(i).getCpf());
contNetos=3;
guardaNomeN3 = v.get(i).getNome();
}
else
if(contNetos==1){
relatorios.setNomeN4(v.get(i).getNome());
relatorios.setCpfN4(v.get(i).getCpf());
contNetos=4;
guardaNomeN4 = v.get(i).getNome();
}
}
else
if((v.get(i).getGrauNaMatriz().equals("BISNETO")) && (v.get(i).getNome().equals(guardaNomeN1))){
if(contBisnetos1==0){
relatorios.setNomeB1(v.get(i).getNome());
relatorios.setCpfB1(v.get(i).getCpf());
contBisnetos1 = 1;
}
else
if(contBisnetos1==1){
relatorios.setNomeB2(v.get(i).getNome());
relatorios.setCpfB2(v.get(i).getCpf());
}
}
else
if((v.get(i).getGrauNaMatriz().equals("BISNETO")) && (v.get(i).getNome().equals(guardaNomeN2))){
if(contBisnetos2==0){
relatorios.setNomeB3(v.get(i).getNome());
relatorios.setCpfB3(v.get(i).getCpf());
contBisnetos2 = 1;
}
else
if(contBisnetos2==1){
relatorios.setNomeB4(v.get(i).getNome());
relatorios.setCpfB4(v.get(i).getCpf());
}
}
else
if((v.get(i).getGrauNaMatriz().equals("BISNETO")) && (v.get(i).getNome().equals(guardaNomeN3))){
if(contBisnetos3==0){
relatorios.setNomeB5(v.get(i).getNome());
relatorios.setCpfB5(v.get(i).getCpf());
contBisnetos3 = 1;
}
else
if(contBisnetos3==1){
relatorios.setNomeB6(v.get(i).getNome());
relatorios.setCpfB6(v.get(i).getCpf());
}
}
else
if((v.get(i).getGrauNaMatriz().equals("BISNETO")) && (v.get(i).getNome().equals(guardaNomeN4))){
if(contBisnetos4==0){
relatorios.setNomeB7(v.get(i).getNome());
relatorios.setCpfB7(v.get(i).getCpf());
contBisnetos4 = 1;
}
else
if(contBisnetos4==1){
relatorios.setNomeB8(v.get(i).getNome());
relatorios.setCpfB8(v.get(i).getCpf());
}
}
/* Colocando o Pai no vetor de Relatórios*/
if(relatorios.getNomePai()==null){
relatorios.setNomePai("");
relatorios.setCpfPai("");
}
v2.get(i).setNomePai(relatorios.getNomePai());
v2.get(i).setCpfPai(relatorios.getCpfPai());
/*Colocando os filhos no vetor de Relatórios*/
if(relatorios.getNomeF1()==null){
relatorios.setNomeF1("");
relatorios.setCpfF1("");
}
v2.get(i).setNomeF1(relatorios.getNomeF1());
v2.get(i).setCpfF1(relatorios.getCpfF1());
if(relatorios.getNomeF2()==null){
relatorios.setNomeF2("");
relatorios.setCpfF2("");
}
v2.get(i).setNomeF2(relatorios.getNomeF2());
v2.get(i).setCpfF2(relatorios.getCpfF2());
/*Colocando os netos no vetor de Relatórios*/
if(relatorios.getNomeN1()==null){
relatorios.setNomeN1("");
relatorios.setCpfN1("");
}
v2.get(i).setNomeN1(relatorios.getNomeN1());
v2.get(i).setCpfN1(relatorios.getCpfN1());
if(relatorios.getNomeN2()==null){
relatorios.setNomeN2("");
relatorios.setCpfN2("");
}
v2.get(i).setNomeN2(relatorios.getNomeN2());
v2.get(i).setCpfN2(relatorios.getCpfN2());
if(relatorios.getNomeN3()==null){
relatorios.setNomeN3("");
relatorios.setCpfN3("");
}
v2.get(i).setNomeN3(relatorios.getNomeN3());
v2.get(i).setCpfN3(relatorios.getCpfN3());
if(relatorios.getNomeN4()==null){
relatorios.setNomeN4("");
relatorios.setCpfN4("");
}
v2.get(i).setNomeN4(relatorios.getNomeN4());
v2.get(i).setCpfN4(relatorios.getCpfN4());
/*Colocando os bisnetos no vetor de Relatórios*/
if(relatorios.getNomeB1()==null){
relatorios.setNomeB1("");
relatorios.setCpfB1("");
}
v2.get(i).setNomeB1(relatorios.getNomeB1());
v2.get(i).setCpfB1(relatorios.getCpfB1());
if(relatorios.getNomeB2()==null){
relatorios.setNomeB2("");
relatorios.setCpfB2("");
}
v2.get(i).setNomeB2(relatorios.getNomeB2());
v2.get(i).setCpfB2(relatorios.getCpfB2());
if(relatorios.getNomeB3()==null){
relatorios.setNomeB3("");
relatorios.setCpfB3("");
}
v2.get(i).setNomeB3(relatorios.getNomeB3());
v2.get(i).setCpfB3(relatorios.getCpfB3());
if(relatorios.getNomeB4()==null){
relatorios.setNomeB4("");
relatorios.setCpfB4("");
}
v2.get(i).setNomeB4(relatorios.getNomeB4());
v2.get(i).setCpfB4(relatorios.getCpfB4());
if(relatorios.getNomeB5()==null){
relatorios.setNomeB5("");
relatorios.setCpfB5("");
}
v2.get(i).setNomeB5(relatorios.getNomeB5());
v2.get(i).setCpfB5(relatorios.getCpfB5());
if(relatorios.getNomeB6()==null){
relatorios.setNomeB6("");
relatorios.setCpfB6("");
}
v2.get(i).setNomeB6(relatorios.getNomeB6());
v2.get(i).setCpfB6(relatorios.getCpfB6());
if(relatorios.getNomeB7()==null){
relatorios.setNomeB7("");
relatorios.setCpfB7("");
}
v2.get(i).setNomeB7(relatorios.getNomeB7());
v2.get(i).setCpfB7(relatorios.getCpfB7());
if(relatorios.getNomeB8()==null){
relatorios.setNomeB8("");
relatorios.setCpfB8("");
}
v2.get(i).setNomeB8(relatorios.getNomeB8());
v2.get(i).setCpfB8(relatorios.getCpfB8());
} //fim do for
O problema está no seguinte... tenho que inicializar o Vector Relatórios com null.. mas por algum motivo.. quando tento setar os valores dele através da chamada v2.get(i).setNomeB6(relatorios.getNomeB6()); por exemplo ele está dando nullPonterException...
Não estou descobrindo o por quê!!
Me juda ae galeraaaaaaaaaa!!!