I recently started using OpenCSV's CSVReader to get data from a CSV file to a JTable in java, but I keep getting an error. DaTroop gave the answer to how to get data from the CSV here: import csv to JTable . In my case I copied the code
CSVReader reader = new CSVReader(new FileReader("yourfile.csv"));
List myEntries = reader.readAll();
JTable table = new JTable(myEntries.toArray());
into Netbeans IDE 7.4, but I keep getting the error "Incompatible types - Object Cannot be converted to TableModel". in the
(myEntries.toArray());
Any ideas?
Thanks
As in comment, please find my whole code snippet. The JFrame works and views, so it should be called fine.
public static void LoadLog() throws FileNotFoundException, IOException {
LogViewer log = new LogViewer();
log.setVisible(true);
CSVReader reader = new CSVReader(new FileReader("testog.csv"));
String[][] rowData = {
{ "A", "B" },
{ "C", "D" }
};
List<String[]> myEntries = reader.readAll();
rowData = myEntries.toArray(new String[0][]);
String[] columnNames = { "Column 1", "Column 2" };
System.out.println(myEntries);
table1 = new JTable(rowData, columnNames);
log.pack();
log.setVisible(true);
}