JTable ClassCastException : Help please

Discussion in 'Java' started by suresh.gn@gmail.com, Jul 11, 2006.

  1. Guest

    Dear Java experts,

    I have a JTable problem here.
    Problem description: I have to display a default table(3X3) when the
    application launches for the first time. Then user should able to
    modify the table and my application should able to read the changed
    values in this table. Please have a look at the below code.

    Table3.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){

    for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
    try{
    t3[j] =
    ((Integer)data3[j]).intValue();
    }catch(ClassCastException cce){}
    }
    }
    table3.getModel().addTableModelListener(new
    TableModelListener(){
    public void tableChanged(TableModelEvent e) {
    int row = e.getFirstRow();
    int column = e.getColumn();
    TableModel model = (TableModel)e.getSource();
    String columnName = model.getColumnName(column);
    Object data3 = model.getValueAt(row, column);
    t3[row][column] = new
    Integer((String)data3).intValue();
    }
    });
    }
    });

    here table3 is a JTable
    Table3 is the radio button used to select that matrix
    data3 is an Object[][] with column names for JTable
    t3 is the default matrix used and modified by the user.

    When I use this code, my application throwing ClassCastException
    because of converting data3 to t3. Can any body help me?
    , Jul 11, 2006
    #1
    1. Advertising

  2. Oliver Wong Guest

    <> wrote in message
    news:...
    > Dear Java experts,
    >
    > I have a JTable problem here.
    > Problem description: I have to display a default table(3X3) when the
    > application launches for the first time. Then user should able to
    > modify the table and my application should able to read the changed
    > values in this table. Please have a look at the below code.
    >
    > Table3.addActionListener(new ActionListener(){
    > public void actionPerformed(ActionEvent e){
    >
    > for(int i = 0; i < 3; i++){
    > for(int j = 0; j < 3; j++){
    > try{
    > t3[j] =
    > ((Integer)data3[j]).intValue();
    > }catch(ClassCastException cce){}
    > }
    > }
    > table3.getModel().addTableModelListener(new
    > TableModelListener(){
    > public void tableChanged(TableModelEvent e) {
    > int row = e.getFirstRow();
    > int column = e.getColumn();
    > TableModel model = (TableModel)e.getSource();
    > String columnName = model.getColumnName(column);
    > Object data3 = model.getValueAt(row, column);
    > t3[row][column] = new
    > Integer((String)data3).intValue();
    > }
    > });
    > }
    > });
    >
    > here table3 is a JTable
    > Table3 is the radio button used to select that matrix
    > data3 is an Object[][] with column names for JTable
    > t3 is the default matrix used and modified by the user.
    >
    > When I use this code, my application throwing ClassCastException
    > because of converting data3 to t3. Can any body help me?
    >


    The data3 on the 8th line of code that you posted never gets declared
    anywhere. Please post an SSCCE: http://mindprod.com/jgloss/sscce.html

    - Oliver
    Oliver Wong, Jul 11, 2006
    #2
    1. Advertising

  3. Guest

    data3 is Object[][] data3 = { {1,1,1},
    {1,1,1},
    {1,1,1}
    };
    Oliver Wong wrote:
    > <> wrote in message
    > news:...
    > > Dear Java experts,
    > >
    > > I have a JTable problem here.
    > > Problem description: I have to display a default table(3X3) when the
    > > application launches for the first time. Then user should able to
    > > modify the table and my application should able to read the changed
    > > values in this table. Please have a look at the below code.
    > >
    > > Table3.addActionListener(new ActionListener(){
    > > public void actionPerformed(ActionEvent e){
    > >
    > > for(int i = 0; i < 3; i++){
    > > for(int j = 0; j < 3; j++){
    > > try{
    > > t3[j] =
    > > ((Integer)data3[j]).intValue();
    > > }catch(ClassCastException cce){}
    > > }
    > > }
    > > table3.getModel().addTableModelListener(new
    > > TableModelListener(){
    > > public void tableChanged(TableModelEvent e) {
    > > int row = e.getFirstRow();
    > > int column = e.getColumn();
    > > TableModel model = (TableModel)e.getSource();
    > > String columnName = model.getColumnName(column);
    > > Object data3 = model.getValueAt(row, column);
    > > t3[row][column] = new
    > > Integer((String)data3).intValue();
    > > }
    > > });
    > > }
    > > });
    > >
    > > here table3 is a JTable
    > > Table3 is the radio button used to select that matrix
    > > data3 is an Object[][] with column names for JTable
    > > t3 is the default matrix used and modified by the user.
    > >
    > > When I use this code, my application throwing ClassCastException
    > > because of converting data3 to t3. Can any body help me?
    > >

    >
    > The data3 on the 8th line of code that you posted never gets declared
    > anywhere. Please post an SSCCE: http://mindprod.com/jgloss/sscce.html
    >
    > - Oliver
    , Jul 12, 2006
    #3
  4. Oliver Wong Guest

    [post re-ordered]

    <> wrote in message
    news:...
    > Oliver Wong wrote:
    >> <> wrote in message
    >> news:...
    >> > ((Integer)data3[j]).intValue();

    [...]
    >>
    >> The data3 on the 8th line of code that you posted never gets declared
    >> anywhere. Please post an SSCCE: http://mindprod.com/jgloss/sscce.html
    >>
    >> - Oliver

    >
    > data3 is Object[][] data3 = { {1,1,1},
    > {1,1,1},
    > {1,1,1}
    > };


    Why don't you declare data3 as being an int[][] and not casting to
    Integer?

    - Oliver
    Oliver Wong, Jul 12, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tivo Escobar
    Replies:
    1
    Views:
    7,243
    manusa
    Apr 12, 2007
  2. KK
    Replies:
    2
    Views:
    500
    Big Brian
    Oct 14, 2003
  3. Tintin92
    Replies:
    1
    Views:
    1,665
    Andrew Thompson
    Feb 14, 2007
  4. Luiss
    Replies:
    4
    Views:
    1,231
  5. Haircuts Are Important
    Replies:
    3
    Views:
    293
    Haircuts Are Important
    Jun 4, 2013
Loading...

Share This Page