-
December 5th, 2008, 11:48 AM
#1
Little help thanks in advance! :D
Ok, my problem is I have an issue with a button on my program.
I have a JTable I need to read, the problem is, everytime I try to, a Null Pointer Exception jumps out, and then reads the first line of the JTable. The problem, I don't want that exception to jump everytime the JTable has a null space.
this is my code on the for loop to read the JTable:
Code:
for(int z=0;z<tablaGenera.getRowCount();++z)
{
for(int y=0;y<tablaGenera.getColumnCount();++y)
{
String tabla= tablaGenera.getValueAt(z,y).toString();
System.out.print(tabla+",");
}
}
Please help me, I perhaps am missing something I didn't learned well. If I have only 1 line on the JTable, I get the NullPointer Exception, but if my Table is all filled with data (no null spaces) then I get no Exception. And what I need is it to read without any error even if there's only 1 line.
Thanks in advance :3
-
December 5th, 2008, 12:06 PM
#2
Re: Little help thanks in advance! :D
The problem is that you are trying to call the .toString() method on objects that are null. You can prevent this, or catch this.
Prevent:
if(table.getValueAt(x,y) != null) {
table.getValueAt(x,y).toString();
}
Catch it (not recommended)
try {
table.getValueAt(x,y).toString();
} catch(NullPointerException e) {
//silently ignore the expected error
}
-
December 5th, 2008, 01:48 PM
#3
Re: Little help thanks in advance! :D
Ok, thx very much.. it helped me a lot! :3
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|