我的代码有什么错误,为什么报java.lang.String cannot be cast to java.util.Vector
代码:
DefaultTableModel tableModel = new DefaultTableModel();
Vector<String> columnNames = new Vector();
columnNames.addElement("日期");// {"日期","类别","分类","多少钱","卡/现金","说明"};
columnNames.addElement("类别");
columnNames.addElement("分类");
columnNames.addElement("多少钱");
columnNames.addElement("卡/现金");
columnNames.addElement("说明");
Vector rowData = new Vector();
rowData.addElement("1");
//rowData.addElement(string);
tableModel.setDataVector(rowData, columnNames);
table.setModel(tableModel);
------解决方案--------------------
rowData需要增加的是个vector。因为一行会有多列。
所以Vector<Vector<String>> rowData = new Vector<Vector<String>>();
Vector<String> oneRow = new Vector<String>();
oneRow.addElement("1");
oneRow.addElement("1");
oneRow.addElement("1");
oneRow.addElement("1");
oneRow.addElement("1");
oneRow.addElement("1");
rowData.addElement(oneRow);
------解决方案--------------------
dataVector是一个矢量的矢量
Vector rowData = new Vector();
Vector rowData1 = new Vector();
rowData1.addElement("aaaaaaaa");
rowData.addElement(rowData);
//rowData.addElement(string);
tableModel.setDataVector(rowData, columnNames);
这样就可以用了