I have XML parsed data that I am trying to add into a DefaultTableModel. The DefaultTableModel takes in Vectors or Object[] as argument according to the documentation.
But when I use a Vector I get this exception :
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Vector
This is the class I am using to parse and add into the vector .
public class PropXMLParsing {
static PropXMLParsing instance = null;
private Vector<String> header = new Vector<String>();
private Vector<String> data = new Vector<String>();
public static PropXMLParsing getInstance() {
if (instance == null) {
instance = new PropXMLParsing();
try {
instance.ParserForObjectTypes();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
}
return instance;
}
public void ParserForObjectTypes() throws SAXException, IOException,
ParserConfigurationException {
try {
FileInputStream file = new FileInputStream(new File(
"xmlFiles/CoreDatamodel.xml"));
DocumentBuilderFactory builderFactory = DocumentBuilderFactory
.newInstance();
DocumentBuilder builder = builderFactory.newDocumentBuilder();
Document xmlDocument = builder.parse(file);
XPath xPath = XPathFactory.newInstance().newXPath();
String expression = "//prop/*";
NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(
xmlDocument, XPathConstants.NODESET);
for (int i = 0; i < nodeList.getLength(); i++) {
System.out.println(nodeList.item(i).getFirstChild()
.getNodeValue());
data.addElement(nodeList.item(i).getFirstChild().getNodeValue());
header.addElement(nodeList.item(i).getFirstChild()
.getNodeValue());
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (XPathExpressionException e) {
e.printStackTrace();
}
}
public Vector<String> getHeader() {
return header;
}
public Vector<String> getData() {
return data;
}
}
And this last line of code is where it cast exception. This is from my GUI class :
model = new DefaultTableModel(PropXMLParsing.getInstance().getHeader(),
PropXMLParsing.getInstance().getData());
table = new JTable(model);
Help me please