ベクターに値を保存しようとしているときに、java.lang.NullPointerExceptionを受け取り続けます。XMLドキュメントは次のとおりです。
<?xml version="1.0" standalone="yes"?>
<autocomplete>
<autocomplete_item>
<title short="Forrest Gump"></title>
</autocomplete_item>
<autocomplete_item>
<title short="Forrest Landis"></title>
</autocomplete_item>
<autocomplete_item>
<title short="Finding Forrester"></title>
</autocomplete_item>
<autocomplete_item>
<title short="Menotti: The Medium: Maureen Forrester"></title>
</autocomplete_item>
</autocomplete>
そして、これが私の更新されたコードです:
import java.util.Vector;
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;
public class SearchParse extends DefaultHandler {
Vector titles;
public SearchParse() {
}
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
int length = attributes.getLength();
for (int i = 0; i < length; i++) {
String value = attributes.getValue(i);
titles.addElement(value);
}
}
public Vector getTitles() {
return titles;
}
}
NullPointerExceptionは次の行で発生しています。
titles.addElement(value);
なぜこれなのか誰か知っていますか?ありがとう!