Java – get the value from JTable as an integer?

I don't understand; I am using defaulttablemodel. My attempt is to get the values in the table as ints:

Integer.parseInt( tableModel.getValueAt(i,1) );

Eclipse says that a cast is required from object to string, so eclipse makes:

Integer.parseInt( (String) tableModel.getValueAt(i,1) );

At run time, the program crashed because "int" could not be converted to string Why? I expect "object – > string – > int"

Solution

Try using:

Integer.parseInt( tableModel.getValueAt(i,1).toString() );

Just use tostring() to set the string representation of the object

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>