Pessoal é o seguinte:
tenho um metodo aqui que acessa um xml e retorna uma collection.
a estrutura do meu xml é a seguinte:
<?xml version="1.0" encoding="iso-8859-1" ?>
- <MUNICIPIO>
- <DATA_RECORD>
<CODIGO>63808000</CODIGO>
<DESCRICAO>2 DTS MIRANDELA(R POMBAL)</DESCRICAO>
<UF>BA</UF>
</DATA_RECORD>
- <DATA_RECORD>
<CODIGO>60160000</CODIGO>
<DESCRICAO>A. DO PAULISTA</DESCRICAO>
<UF>BA</UF>
</DATA_RECORD> ... etc..
descrição do municipio [nodelist.item(i).getChildNodes().item(1).getChildNodes().item(0).getNodeValue()] e a
UF [nodelist.item(i).getChildNodes().item(2).getChildNodes().item(0).getNodeValue() ] em minha XML.
... Mas quando rodo no .jar, meu metódo não consegue mais achar a descrição e a UF(java.lang.NullPointerException).
Inclusive quando chamo [nodelist.item(i).getChildNodes().item(1).getChildNodes().item(0).getNodeValue()] que
seria a Descrição, ele acaba trazendo o Código...
Pq no IDE meu código ele consegue encontrar tudo no XML .. Roda certinho..
Mas no .jar ele não consegue mais ? Alguém sabe o porquê ?
Valeu !
Segue o metodo que uso:
************************************************************
public Collection obterMunicipioUf(UfModel pUf)
{
Collection lCol = new ArrayList();
java.net.URL URLTipoProcesso;
String xml="";
try
{
BufferedInputStream buff = new BufferedInputStream(URLTipoProcesso.openStream());
int length = buff.available();
byte[] bytes = new byte[length];
buff.read(bytes);
xml = new String(bytes);
}
catch (IOException e)
{
e.printStackTrace();
}
try
{
Document doc = Util.parseXmlFile(xml);
String xpath = "/MUNICIPIO/DATA_RECORD[UF=\""+pUf.getUf().trim()+"\"]";
NodeList nodelist = org.apache.xpath.XPathAPI.selectNodeList(doc, xpath);
[i] for(int i=0;i<nodelist.getLength();i++){
MunicipioModel lMunicipio = new MunicipioModel();
lMunicipio.setCodigo(new Long(nodelist.item(i).getChildNodes().item(0).getChildNodes().item(0).getNodeValue())); [b]//NO .JAR GERA A EXCEÇÃO AQUI !! java.lang.NullPointerException.[/b]
lMunicipio.setDescricao(nodelist.item(i).getChildNodes().item(1).getChildNodes().item(0).getNodeValue()); [b]// E AQUI ELE CABA TRAZENDO O CÓDIGO AO INVEZ DA DESCRIÇÃO...[/b]
lCol.add(lMunicipio);[/i]
}
}
catch (javax.xml.transform.TransformerException e)
{
e.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}
return lCol;
}