I have a problem with downloading the number from JTable. In Eclipse I have jre JavaSE 1.7 and it is all ok. I opened my project in IntelliJ IDEA and chose SDK java jdk 1.8.
private int;
public void tableEdit(final JTable table) {
table.getModel().addTableModelListener(new TableModelListener() {
@Override
public void tableChanged(TableModelEvent e) {
// TODO Auto-generated method stub
if (table.getCellEditor() != null) {
int col = table.getSelectedColumn();
id = (int)table.getValueAt(table.getSelectedRow(), 0); //ERROR
Error:
java: incompatible types: java.lang.Object cannot be converted to int
Edit:
New problem: The JTable I have 2 fields, ID and field2 (combobox) after selecting the value from the combobox wants to retrieve a value from the ID field so that they know which row I need to update.
categoryBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent event) {
if (newrow_flag == 0) {
JComboBox comboBox = (JComboBox) event.getSource();
Object item = event.getItem();
if (event.getStateChange() == ItemEvent.SELECTED
&& box_flag_category > 0) {
Category selected_category = (Category) categoryBox
.getSelectedItem();
int rowid = Integer.getInteger(itemTable.getValueAt(
itemTable.getSelectedRow(), 0).toString()); //Error
id_category = selected_category.getId();
fireItemEvent(new ItemsEvent(rowid, "produkty", null,
null, null, id_category, id_company, "update"),
"box_category");
}
box_flag_category++;
}
}
});
And error:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at com.magazyn.view.View$9.itemStateChanged(View.java:659)
at javax.swing.JComboBox.fireItemStateChanged(JComboBox.java:1223)
at javax.swing.JComboBox.selectedItemChanged(JComboBox.java:1280)
at javax.swing.JComboBox.contentsChanged(JComboBox.java:1327)
at javax.swing.AbstractListModel.fireContentsChanged(AbstractListModel.java:118)
at javax.swing.DefaultComboBoxModel.setSelectedItem(DefaultComboBoxModel.java:93)
at javax.swing.JComboBox.setSelectedItem(JComboBox.java:576)
at javax.swing.JComboBox.setSelectedIndex(JComboBox.java:622)
at javax.swing.plaf.basic.BasicComboPopup$Handler.mouseReleased(BasicComboPopup.java:834)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:290)
at java.awt.Component.processMouseEvent(Component.java:6527)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
[...]
Error points to this line:
int rowid = Integer.getInteger(itemTable.getValueAt(
itemTable.getSelectedRow(), 0).toString());