Results 1 to 10 of 10
- 12-02-2009, 09:12 PM #1
Senior Member
- Join Date
- Sep 2009
- Location
- Sweden/Borås
- Posts
- 107
- Rep Power
- 0
Write empty Jtable columns to disk
<SOLVED>
Evening all.
Have this small problem, if i happen to have an empty column when i save the data from JTable to disk, it erase all data stored in the file and cast a
Java Code:Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
I use Vectors with DefaultTableModel. Mabey I can solve it within the try and catch part? Or you guys have a better ide?Last edited by ocean; 12-03-2009 at 03:03 PM. Reason: Solved this. and dont know how to mark it "Solved"
- 12-02-2009, 09:15 PM #2
Senior Member
- Join Date
- Nov 2009
- Posts
- 150
- Rep Power
- 4
post a bit of your code?
- 12-02-2009, 09:22 PM #3
Senior Member
- Join Date
- Sep 2009
- Location
- Sweden/Borås
- Posts
- 107
- Rep Power
- 0
This is the method for saving it to disk.
Java Code:void writeProject(String fileName){ // Finish editing the current cell before saving if (custTable.isEditing() ){ int row =custTable.getEditingRow(); int col =custTable.getEditingColumn(); custTable.getCellEditor(row, col).stopCellEditing(); } int rows = custTable.getRowCount(); int columns = custTable.getColumnCount(); TableColumnModel header =custTable.getColumnModel(); try { FileWriter fw = new FileWriter("/home/magnus/NetBeansProjects/files/" + fileName +".cust"); BufferedWriter out = new BufferedWriter (fw); // Write out the Column Headers for (int k = 0; k < columns; k++){ TableColumn column = header.getColumn(k); String value = (String)column.getHeaderValue(); out.write(value); out.write("|"); } out.newLine(); // Write out the table rows for (int j = 0; j < rows; j++){ for (int k = 0; k < columns; k++){ String value = (String)custTable.getValueAt(j, k); out.write(value); out.write("|"); } out.newLine(); } out.close(); }catch(IOException ee) { throw new RuntimeException(ee); } } // END WriteProject/
- 12-02-2009, 09:29 PM #4
Senior Member
- Join Date
- Nov 2009
- Posts
- 150
- Rep Power
- 4
the line befor out.close(); write out.flush();
does it saves now?
- 12-02-2009, 09:31 PM #5
Senior Member
- Join Date
- Nov 2009
- Posts
- 150
- Rep Power
- 4
and by the way, does it saves sometimes?
or does it always give a nullpointer exception?
- 12-02-2009, 09:34 PM #6
Senior Member
- Join Date
- Sep 2009
- Location
- Sweden/Borås
- Posts
- 107
- Rep Power
- 0
It saves fine if there is a value in every column.
- 12-02-2009, 09:46 PM #7
Senior Member
- Join Date
- Sep 2009
- Location
- Sweden/Borås
- Posts
- 107
- Rep Power
- 0
Think i migth get it solved. Trying something like
Just gonna come up something good for the code part.Java Code:if (value == null){ code }
- 12-03-2009, 07:10 AM #8
Senior Member
- Join Date
- Nov 2009
- Posts
- 150
- Rep Power
- 4
what's in your file when you save it if not every collumn has a value?
- 12-03-2009, 08:28 AM #9
Senior Member
- Join Date
- Sep 2009
- Location
- Sweden/Borås
- Posts
- 107
- Rep Power
- 0
If i save with a collumn = null it erase all data stored in the file.
Not sure yet how Im gonna handle this. Do I want the user to be able to save null columns or should i make sure he/she fills them. Makes more sence to allow user to save empty data i guess.
- 12-03-2009, 03:02 PM #10
Senior Member
- Join Date
- Sep 2009
- Location
- Sweden/Borås
- Posts
- 107
- Rep Power
- 0
Similar Threads
-
Sorting and hiding columns in JTable
By ProgrammingPup in forum Advanced JavaReplies: 1Last Post: 11-17-2009, 09:59 PM -
Sorting JTable on more than just the values listed in the columns
By Jeegen in forum AWT / SwingReplies: 7Last Post: 09-23-2009, 07:28 PM -
How to sort a JTable for multiple columns?
By BLR in forum Advanced JavaReplies: 2Last Post: 03-16-2009, 10:41 AM -
Right Align columns in JTable
By Laura Warren in forum New To JavaReplies: 2Last Post: 12-18-2008, 09:01 PM -
sort columns in jtable
By Alan in forum AWT / SwingReplies: 2Last Post: 05-14-2007, 05:18 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks