java.lang.Object cannot be converted to int

lukassz

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());
christopher

Well look at the error:

java: incompatible types: java.lang.Object cannot be converted to int

And then look at the line that throws the error:

id =  (int)table.getValueAt(table.getSelectedRow(), 0);

Now as you can see, you're attempting to cast an Object to an int. This is not allowed. So you need to be a little more creative:

int id = Integer.parseInt(table.getValueAt(table.getSelectedRow(), 0).toString()); 

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

java.lang.Object cannot be converted to boolean

From Dev

JAVA: Incompatible types: int cannot be converted to java.lang.String

From Dev

java.lang.object cannot be converted to (selfmade class)

From Dev

java.lang.object cannot be converted to (selfmade class)

From Dev

Java int cannot be converted to boolean

From Dev

getting java.lang.Object cannot be converted to java.lang.Integer

From Dev

incompatible types - int cannot be converted in to java.lang.string -java - bluej

From Java

Java incompatible types: int cannot be converted to int[]

From Dev

Java incompatible types: int cannot be converted to int[]

From Dev

java.lang.String cannot be converted to JSONArray

From Dev

java.lang.String cannot be converted to JSONObject

From Dev

How do I solved java.lang.String cannot converted to JSON object?

From Java

Java : incompatible types; int cannot be converted to string

From Dev

int[][] cannot be converted into int

From Dev

int cannot be converted to int []

From Dev

Type safe merging of Map with multiple types for its value; `incompatible types java.lang.Object cannot be converted to capture#1 of ?`

From Dev

org.json.JSONException: Value of Feedback type java.lang.String cannot be converted to JSONArray while converting jsonstring to object

From Dev

double[][] cannot be converted to int[][]

From Dev

JSONException: Value of type java.lang.String cannot be converted to JSONObject

From Dev

Value Database of type java.lang.String cannot be converted to JSONObject

From Dev

Value Bundle of type java.lang.String cannot be converted to JSONArray

From Dev

JSONArray java.lang.String cannot be converted to JSONObject

From Dev

JSON Exception: java.lang.String cannot be converted to JSONObject

From Dev

Value Database of type java.lang.String cannot be converted to JSONObject

From Dev

Value Bundle of type java.lang.String cannot be converted to JSONArray

From Dev

Value Connected of type java.lang.String cannot be converted to JSONObject

From Dev

Why java.lang.String cannot converted into JSONObject in android

From Dev

java.lang.String cannot be converted to JSONObject. mismatch type

From Dev

Java: toString error "error: incompatible types: int cannot be converted to String"

Related Related

  1. 1

    java.lang.Object cannot be converted to boolean

  2. 2

    JAVA: Incompatible types: int cannot be converted to java.lang.String

  3. 3

    java.lang.object cannot be converted to (selfmade class)

  4. 4

    java.lang.object cannot be converted to (selfmade class)

  5. 5

    Java int cannot be converted to boolean

  6. 6

    getting java.lang.Object cannot be converted to java.lang.Integer

  7. 7

    incompatible types - int cannot be converted in to java.lang.string -java - bluej

  8. 8

    Java incompatible types: int cannot be converted to int[]

  9. 9

    Java incompatible types: int cannot be converted to int[]

  10. 10

    java.lang.String cannot be converted to JSONArray

  11. 11

    java.lang.String cannot be converted to JSONObject

  12. 12

    How do I solved java.lang.String cannot converted to JSON object?

  13. 13

    Java : incompatible types; int cannot be converted to string

  14. 14

    int[][] cannot be converted into int

  15. 15

    int cannot be converted to int []

  16. 16

    Type safe merging of Map with multiple types for its value; `incompatible types java.lang.Object cannot be converted to capture#1 of ?`

  17. 17

    org.json.JSONException: Value of Feedback type java.lang.String cannot be converted to JSONArray while converting jsonstring to object

  18. 18

    double[][] cannot be converted to int[][]

  19. 19

    JSONException: Value of type java.lang.String cannot be converted to JSONObject

  20. 20

    Value Database of type java.lang.String cannot be converted to JSONObject

  21. 21

    Value Bundle of type java.lang.String cannot be converted to JSONArray

  22. 22

    JSONArray java.lang.String cannot be converted to JSONObject

  23. 23

    JSON Exception: java.lang.String cannot be converted to JSONObject

  24. 24

    Value Database of type java.lang.String cannot be converted to JSONObject

  25. 25

    Value Bundle of type java.lang.String cannot be converted to JSONArray

  26. 26

    Value Connected of type java.lang.String cannot be converted to JSONObject

  27. 27

    Why java.lang.String cannot converted into JSONObject in android

  28. 28

    java.lang.String cannot be converted to JSONObject. mismatch type

  29. 29

    Java: toString error "error: incompatible types: int cannot be converted to String"

HotTag

Archive