I am making a restaurant ordering system menu for homework in Java. I am to make a receipt in the form of the program creating a text file with the table contents in it. I am however having trouble doing this. All my table contents are strings.
This is the code for exporting the contents of the table:
try{
BufferedWriter bfw = new BufferedWriter(new FileWriter("Data.txt"));
for(int i = 0 ; i < tableSalesFood.getColumnCount() ; i++){
bfw.write(tableSalesFood.getColumnName(i));
bfw.write("\t");
}
for (int i = 0 ; i < tableSalesFood.getRowCount(); i++){
bfw.newLine();
for(int j = 0 ; j < tableSalesFood.getColumnCount();j++){
bfw.write((String)(tableSalesFood.getValueAt(i,j)));
bfw.write("\t");;
}
}
bfw.close();
}catch(Exception ex){
ex.printStackTrace();
}
The program returns the exception error when I click the button:
java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String