Buenas, tengo un problema con un ejercicio de clase en el qual recibo un valor nulo pero no se encontrarlo, adjunto el codigo y el error a ver si alguien me puede ayudar
El error
Código:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at LectorXML.endElement(LectorXML.java:95)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at App$ClickGenerate.actionPerformed(App.java:209)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$400(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
La pagina LectorXML.java:
Código:
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
/**
* Classe que sobreescriu alguns dels mètodes de DefaultHandler per tal d'analitzar
* arxius XML en format RSS.
*
* @author Jordi Gual i Purtí
*
*/
public class LectorXML extends DefaultHandler {
private ArrayList<Lectura> Lecturas;
private Lectura LecturaActual;
private boolean parsejantNoticia = false;
private String valor;
/**
* Mètode que s'executa quan s'inicia l'anàlisi del contingut XML.
*/
public void startDocument() throws SAXException {
Lecturas = new ArrayList<Lectura>();
}
/**
* Mètode que s'executa cada cop que el parser detecta que s'obre un tag XML.
*/
public void startElement(
String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
if (qName.equals("record")) {
Lecturas.add(LecturaActual);
parsejantNoticia = true;
}
else {
valor = "";
}
}
/**
* Mètode que s'executa quan estam llegin caràcters del contigut d'algun tag XML.
*/
public void characters(char[] ch, int start, int length) throws SAXException {
if (parsejantNoticia) {
valor = valor + new String(ch, start, length);
}
}
/**
* Mètode que s'executa quan el parser detecta que es tanca un tag XML.
*/
public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
if (qName.equals("record")) {
Lecturas.add(LecturaActual);
parsejantNoticia = false;
}
else {
if (parsejantNoticia) {
if (qName.equals("dateTime")) {
SimpleDateFormat sf = new SimpleDateFormat("ddMMyyyyhhmmss");
String str = valor;
Date date = null;
try {
date = sf.parse(str);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
LecturaActual.setDatahora(date);
}
else if (qName.equals("value")) {
LecturaActual.setValue(Double.parseDouble(valor));
}
}
}
}
/**
* Mètode que s'executa quan finalitza l'anàlisi del contingut XML.
*/
public void endDocument() throws SAXException {
System.out.println("Lectures Llegides: " + Lecturas.size());
}
/**
* Mètode getter que ens permetrà tenir accés a l'ArrayList de notícies des de fora
* de la classe per poder consultar-les quan s'hagi acabat l'anàlisi del canal RSS.
*
* @return ArrayList de notícies amb els objectes "Noticia" que contenen les dades
* de les notícies que hem llegit de la font XML-RSS.
*/
public ArrayList<Lectura> getNoticies() {
return Lecturas;
}
}
Si alguien encuentra el error le agradeceria que me lo comunicase